You are not logged in.

#1 2017-11-20 12:06:19

rogorido
Member
Registered: 2009-08-17
Posts: 111

[Solved] Qt: strange behaviour after last qt5-base update

After the qt5-base update (18th nov 2017) I have a very strange behaviour in a small program using QSqlTableModel (with a postgresql database): the model is not populated by data. Other models (QSqlQueryModel) do work perfectly. I don't know whether this is related to the new version of the icu library.

Any hint?

Edit: as I imagine, it was a problem with the qt5-base update. The update to qt5-base 5.9.3(-1) of today (25th nov) solves the problem.

Last edited by rogorido (2017-11-25 14:44:17)

Offline

#2 2017-11-20 12:18:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [Solved] Qt: strange behaviour after last qt5-base update

What is this "small program"?  Is it something you wrote?  Has it been rebuilt since the update?

Why would you suspect icu?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2017-11-20 12:25:08

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

Trilby wrote:

What is this "small program"?  Is it something you wrote?  Has it been rebuilt since the update?

Why would you suspect icu?

Thanks for your answer. "Small program" means a program for my personal use. As far as I know the update of qt5-base two days ago was related to the update of icu (59->60)... Since there QSqlTableModel does not seem to work anymore, which is very strange.

Offline

#4 2017-11-20 12:29:59

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [Solved] Qt: strange behaviour after last qt5-base update

Trilby wrote:

... Is it something you wrote?  Has it been rebuilt since the update?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2017-11-20 12:34:55

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

Trilby wrote:
Trilby wrote:

... Is it something you wrote?  Has it been rebuilt since the update?

yes and yes. Written by me and rebuilt since then.

Offline

#6 2017-11-20 12:53:33

seth
Member
Registered: 2012-09-03
Posts: 51,165

Re: [Solved] Qt: strange behaviour after last qt5-base update

A QSqlTableModel *is* a QSqlQueryModel, so that doesn't make sense to begin with.
libicu deals with unicode - do you use unicode identifiers? How do you determine it's not "populated by data" - by asking row/columnCount() or because your "small program" does somehow™ not work?

Sum up: produce source code and used table if you want assistance on this. It's not possible for anybody else to debug something that's entirely private to you.

Offline

#7 2017-11-20 13:16:39

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

seth wrote:

A QSqlTableModel *is* a QSqlQueryModel, so that doesn't make sense to begin with.
libicu deals with unicode - do you use unicode identifiers? How do you determine it's not "populated by data" - by asking row/columnCount() or because your "small program" does somehow™ not work?

Sum up: produce source code and used table if you want assistance on this. It's not possible for anybody else to debug something that's entirely private to you.

Thank you for your answer. Yes, I know it is complicated to help me. In any case: this small code can illustrate the problem. The QSqlTableModel returns 0 rows. The QsqlQueryModel 1273 (which ist the right number):

#include <QCoreApplication>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlTableModel>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QSqlDatabase db;
    QSqlTableModel model;
    QSqlQueryModel querymodel;

    db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName("localhost");
    db.setDatabaseName("dominicos");
    db.setUserName("igor");

    if (db.open())
        qDebug() << "Abierta";

    // Does not work
    model.setTable("general.places");
    model.select();
    qDebug() << "total " << model.rowCount();

    // Works
    querymodel.setQuery("SELECT * FROM general.places");
    qDebug() << "total " << querymodel.rowCount();

    return a.exec();
}

Offline

#8 2017-11-20 13:20:07

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

I have to add that Qt gives a warning when used with postgesql > 10 because their driver is not update to this version. BUT: this warning did not cause any problem before the last update of qt5-base.

Offline

#9 2017-11-20 13:26:07

seth
Member
Registered: 2012-09-03
Posts: 51,165

Re: [Solved] Qt: strange behaviour after last qt5-base update

"general.places"

Did you try a table name that does not contain a "."?

Technically "general" is not part of the table name, but the scheme - no idea how QSqlTableModel handles this.

Offline

#10 2017-11-20 13:30:52

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

seth wrote:

"general.places"

Did you try a table name that does not contain a "."?

Technically "general" is not part of the table name, but the scheme - no idea how QSqlTableModel handles this.

Thanks again. It does not seem to be the problem. I tried with and without schema, with other schemas (not "general"),... And I get the same problem: QSqlTableModel does not get any data, QSqlQueryModel get the right number of rows. Maybe it is a problem with the driver of Qt for handling postgresql databases, but it is very strange that it worked til Saturday...

Offline

#11 2017-11-20 13:36:28

seth
Member
Registered: 2012-09-03
Posts: 51,165

Re: [Solved] Qt: strange behaviour after last qt5-base update

Well, check your paacman log of friday/saturday ...

Offline

#12 2017-11-20 13:39:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [Solved] Qt: strange behaviour after last qt5-base update

Don't guess; check.

It does seem odd to me that you are using member functions of what looks to be an uninstantiated class.  If a default constructor is being called behind the scenes, then it is being created with a connection to a default (empty) database.

Last edited by Trilby (2017-11-20 13:44:07)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#13 2017-11-20 14:48:07

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

Trilby wrote:

Don't guess; check.

It does seem odd to me that you are using member functions of what looks to be an uninstantiated class.  If a default constructor is being called behind the scenes, then it is being created with a connection to a default (empty) database.

Thanks for the tip. I slightly modified the code. It is extremely strange. With the code I put below I get the following output:

This version of PostgreSQL is not supported and may not work.
Abierta
QSqlError("", "Unable to find table places", "")
"qt_sql_default_connection"
"dominicos"
total  0
total  1243

That means: QSqlTableModel is using the right connection and the right database, but it does not find the table, which is found by QSqlQueryModel. This is very strange, since I can imagine internally QSqlTableModel does simply a "select * from x"...


#include <QCoreApplication>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlTableModel>
#include <QSqlError>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QSqlDatabase db;

    db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName("localhost");
    db.setDatabaseName("dominicos");
    db.setUserName("igor");

    if (db.open())
        qDebug() << "Abierta";

    QSqlTableModel model;
    QSqlQueryModel querymodel;

    // Does not work
    model.setTable("places");
    model.select();
    qDebug() << model.lastError();
    qDebug() << model.database().connectionName();
    qDebug() << model.database().databaseName();
    qDebug() << "total " << model.rowCount();

    // Works
    querymodel.setQuery("SELECT * FROM places");
    qDebug() << "total " << querymodel.rowCount();

    db.close();

    return a.exec();
}

Offline

#14 2017-11-20 15:19:39

progandy
Member
Registered: 2012-05-17
Posts: 5,192

Re: [Solved] Qt: strange behaviour after last qt5-base update

The table model has to read the format of your table with QSqlDatabase::record. If that fails, it might tell you that the table could not be found. Can you do that manually, something like

rec = db.record(tablename)
for i = 0 to rec.count()
    print(rec.fieldName(i))

| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#15 2017-11-20 15:36:40

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [Solved] Qt: strange behaviour after last qt5-base update

Try properly instantiating the class - I can't make heads or tails of what's happening, but I'd not really expect it to work as is.  Figuring out why you're getting that exact error when those classes are used incorrectly doesn't seem like a good use of time, instead first try doing it correctly: see here and try the following after the database has been opened:

QSqlTableModel *model = new QSqlTableModel(Q_NULLPTR, db);
model->setTable("places");
if (model->select() == false)
   qDebug() << model->lastError().text();
qDebug() << "total" << model->rowCount();

Note a few changes: 1) the class is properly instatiated following the example in the library documentation.  2) error information is only checked and printed if the function actually returns an error (any unpredictable garbage may be in the error class if there has not been an error).

Further note this, also from the documentation for rowCount()

Qt docs wrote:

Note: When implementing a table based model, rowCount() should return 0 when the parent is valid.

So perhaps there is no error at all.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#16 2017-11-20 16:01:10

seth
Member
Registered: 2012-09-03
Posts: 51,165

Re: [Solved] Qt: strange behaviour after last qt5-base update

This should be ok'ish because the default database connection should be used - which his code/output confirms to be the case.

Offline

#17 2017-11-20 16:35:05

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

Trilby wrote:

Try properly instantiating the class - I can't make heads or tails of what's happening,..

Thanks for your help. No chance. Same error.

Offline

#18 2017-11-20 16:36:39

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

progandy wrote:

The table model has to read the format of your table with QSqlDatabase::record. If that fails, it might tell you that the table could not be found. Can you do that manually, something like

rec = db.record(tablename)
for i = 0 to rec.count()
    print(rec.fieldName(i))

Thanks, but I don't think the table hast to be read with QSqlDatabase::record...

Offline

#19 2017-11-20 16:43:01

seth
Member
Registered: 2012-09-03
Posts: 51,165

Re: [Solved] Qt: strange behaviour after last qt5-base update

What happens if you replace

model.setTable("places");
model.select();

by

model.setQuery("SELECT * FROM places");

I find the inability to find the table highly suspicious, esp. givin your original invalid table name.

Also: did you check your pacman updates between friday and sunday?

Offline

#20 2017-11-20 16:55:27

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,858
Website

Re: [Solved] Qt: strange behaviour after last qt5-base update

Mod note: moving to programming and scripting


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#21 2017-11-20 16:56:05

progandy
Member
Registered: 2012-05-17
Posts: 5,192

Re: [Solved] Qt: strange behaviour after last qt5-base update

rogorido wrote:

Thanks, but I don't think the table hast to be read with QSqlDatabase::record...

QSqlTableModel has to know which fields are available in the table, so it fetches this information during setTable(). (As an implementation detail, setTable() calls db.record(tablename) for that purpose.) If it cannot get the field names, then the model doesn't try to query for data either. As far as I know, QSqlQueryModel does not do that.

What is the status of model.lastError directly after setTable, but before select()?


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#22 2017-11-20 17:29:34

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

progandy wrote:

What is the status of model.lastError directly after setTable, but before select()?

Thanks again. Same error.

Offline

#23 2017-11-20 17:39:04

rogorido
Member
Registered: 2009-08-17
Posts: 111

Re: [Solved] Qt: strange behaviour after last qt5-base update

seth wrote:

What happens if you replace

model.setTable("places");
model.select();

by

model.setQuery("SELECT * FROM places");

I don't manage to do it... The code you posted does not work because I have to pass a QSqlQuery. If I do so, I get an error that the method is protected...

seth wrote:

Also: did you check your pacman updates between friday and sunday?

Yes. I make everyday updates. qt5-base and other qt packages were updated, but If I look here (https://git.archlinux.org/svntogit/pack … s/qt5-base) I think the update had only to do with the already mentioned update of icu (59-> 60). If I downgrade icu (60 -> 59) qt complains about icu's version and stops compiling.

Offline

#24 2017-11-20 17:50:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [Solved] Qt: strange behaviour after last qt5-base update

When you say you get the "same error" with my suggested revision, does that mean the function returned false indicating an error - or just that the same error text was found in the error class.  To reiterate, reading the error message from an error class when a function call did not fail could have any random result and interpreting that message would be pointless.

Also what about the documentation note I quoted?  It sounds like rowCount is supposed to return zero if all is well under the conditions in which you used it.  As that was initially the only indication of a problem, I fail to see what issue is being chased down here.  It may seem silly for rowCount to return zero, but that is the documented behavior (unless I'm misreading it).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#25 2017-11-20 18:01:47

seth
Member
Registered: 2012-09-03
Posts: 51,165

Re: [Solved] Qt: strange behaviour after last qt5-base update

"model.QSqlQueryModel::setQuery(.)"

Offline

Board footer

Powered by FluxBB