Results 1 to 15 of 15

Thread: QSqlQueryModel::setQuery - SIGSEGV

  1. #1
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSqlQueryModel::setQuery - SIGSEGV

    I'm using Linux / Qt 4.5.0.

    Most sql work is going fine except for this piece of code where I'm using QSqlQueryModel for the first time:

    Qt Code:
    1. QSqlQuery query("SELECT name FROM videosource ");
    2. model->setQuery(query);
    To copy to clipboard, switch view to plain text mode 

    model->setQuery(query) blows out; top of stack is:
    Thread [1] (Suspended: Signal 'SIGSEGV' received. Description: Segmentation fault.)
    36 mysql_stmt_num_rows() 0x046afaa7
    35 QSqlQuery::size() /media/OneTouch4-Main/internet/downloads/QT4.5Preview/qt-x11-opensource-src-4.5.0-snapshot-20081217/src/sql/kernel/qsqlquery.cpp:717 0x00232cfd
    34 QSqlQueryModel::setQuery() /media/OneTouch4-Main/internet/downloads/QT4.5Preview/qt-x11-opensource-src-4.5.0-snapshot-20081217/src/sql/models/qsqlquerymodel.cpp:347 0x00246acf
    ...
    mysql_stmt_num_rows() is presumably in a mysql library somewhere so I'm guessing there is an issue between QSql and mysql.

    (The query "SELECT name FROM videosource" works fine in other situations.)

    Anyone seen this kind of problem before?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Please check your code again, the problem has to be elsewhere. Are you using the database from multiple threads maybe?

  3. #3
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Thank you for your suggestion wysota.

    I extracted the relevant bits of code and tested this threadless morsel:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    5. db.setHostName("localhost");
    6. db.setDatabaseName("mythconverg");
    7. bool trashok;
    8. db.setPort(QString("3306").toInt(&trashok));
    9. db.setUserName("mythtv");
    10. db.setPassword("mythtv");
    11. bool ok = db.open();
    12. if (ok) qDebug() << "Open OK";
    13. else qDebug() << "Open failed";
    14. amodel.setQuery("SELECT sourceid FROM videosource"); //BANG! SIGSEGV
    15. ...
    16. }
    To copy to clipboard, switch view to plain text mode 

    So then I reverted from the Qt 4.5.0 snapshot to 4.4.3. and setQuery then worked as advertised. I will try picking up the latest 4.5 snapshot tomorrow to see if that has fixed anything.

  4. #4
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    I've just tried 4.5.0Beta1. It blows out too.

    There is something fishy about the mysql driver; the working version (4.4.3) of libqsqlmysql.so is larger than the non-working 4.5.0 versions although they were all built the same way with the same set of header files. Am currently investigating but would appreciate any insights.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    try to create QSqlQueryModel in the heap using operator new.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Thanks spirit for the suggestion. Creating on the heap makes no difference.

    Playing around with the debugger gave me the feeling that there was a linkage problem somewhere so in desperation I swapped the 4.5.0 mysql drivers (libqsqlmysql.so & libqsqlmysql.so.debug) for the 4.4.3 versions. Hey presto - everything works.

    I'm not happy about this however as the libraries are not the same size between versions and I'm sure something will bite me soon.

    I've tried recompiling the drivers and Qt itself with different sql options but no joy.

    More suggestions please chaps!

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Do the Qt SQL examples work properly?

  8. #8
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Thanks again wysota. Now why didn't I think of trying the examples?
    Out of the box the sqlqyerymodel examples work fine, but then I found that they use the sqlite drivers.
    If I modify them to use MySql drivers the behaviour is as before: OK with 4.4.3 driver, core dump with 4.5.0.
    Last edited by onamatic; 22nd January 2009 at 00:27. Reason: grammar

  9. #9
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    I've spent a day completely reinstalling MySql, QT and various devel packages; then compiling everything from scratch. Result: No difference at all! Qt4.4.3 works, Qt4.5.0Beta doesn't.

    To recap:

    Qt Code:
    1. amodel.setQuery("SELECT sourceid FROM videosource"); //BANG! SIGSEGV
    To copy to clipboard, switch view to plain text mode 

    Reason for segv: setQuery() eventually calls QMYSQLResult::size in file: $QTDIR/src/sql/drivers/mysql/qsql_mysql.cpp

    Here's the code:
    Qt Code:
    1. int QMYSQLResult::size()
    2. {
    3. if (isSelect())
    4. if (d->d->preparedQuerys)
    5. #if MYSQL_VERSION_ID >= 40108
    6. return int(mysql_stmt_num_rows(d->stmt)); //<---we get here but d->stmt is null
    7. #else
    8. return -1;
    9. #endif
    10. else
    11. return int(mysql_num_rows(d->result)); //<--- d->result is not null, maybe we should have got here
    12. else
    13. return -1;
    14. }
    To copy to clipboard, switch view to plain text mode 

    When mysql_stmt_num_rows(d->stmt) is called it blows because d->stmt is 0x0.
    Well I assume that's the reason; mysql_stmt_num_rows is in a mysql library and expects to see a "struct st_mysql_stmt" pointer.

    I think I'll just put this down to a bug and move on - unless it rings any bells with anyone?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Maybe the problem is not with Qt but with MySQL? Anyway you should report the problem to Qt Software - remember Qt4.5 is still in development phase.

  11. #11
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Will do, thanks for your support.

  12. #12
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Solved!
    The MySql driver in 4.5.0 incorrectly treat this code:
    Qt Code:
    1. model.setQuery("SELECT sourceid FROM videosource");
    To copy to clipboard, switch view to plain text mode 
    as:
    Qt Code:
    1. model.setQuery(QSqlQuery("SELECT sourceid FROM videosource"));
    To copy to clipboard, switch view to plain text mode 
    which is fine except that the QSqlQuery is later treated as a prepared query which it obviously isn't (see annotated code in previous post in this thread); the 4.4.3 driver doesn't make this mistake.
    Workaround:
    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("SELECT sourceid FROM videosource");
    3. query.exec(); //must do this explicitly
    4. model->setQuery(query);
    To copy to clipboard, switch view to plain text mode 

    I have reported this as a bug [#242208].
    Thanks to all for help and support.

  13. #13
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Update:
    The same bug rears its ugly head in this snippet:

    Qt Code:
    1. sourcesTableModel = new QSqlTableModel();
    2. sourcesTableModel->setTable("videosource");
    3. sourcesTableModel->select(); //BANG! SIGSEGV
    To copy to clipboard, switch view to plain text mode 

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    I assure you I'm working with QtSQL almost every day and such statements work just fine Your problem is related strictly to your installation and/or the version of Qt and/or MySQL you are using. If changing the version of Qt doesn't help, try changing the version of MySQL client library you are using.

  15. #15
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQueryModel::setQuery - SIGSEGV

    Thanks wysota - I had similar feedback from QT support regarding my bug report yesterday so I tried the latest snapshot; it works perfectly.

    There had been several developments in qsql_mysql.cpp since the Beta1 release which were directly concerned with my problem.

Similar Threads

  1. QAbstractSocket::abort() with SIGSEGV
    By mtrpoland in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2008, 17:05
  2. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09
  3. QUrlOperator doesn't emit finished signal
    By hayati in forum Qt Programming
    Replies: 16
    Last Post: 26th March 2007, 20:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.