QSqlDatabase open crashes application
-
Same stack trace ?
-
The stack trace on Linux:
0 __GI_____strtoul_l_internal strtol_l.c 298 0x7ffff5b229d7 1 mysql_get_server_version 0x7fffdc8e41bc 2 mysql_set_character_set 0x7fffdc8e4b92 3 ?? 0x7fffdcc7d18e 4 QSqlDatabase::open() 0x7ffff6b1d954 5 UpdateVerifier::getUpdate(QString, int, QString, QString, QString, QString, int) 0x41aadc 6 main main.cpp 23 0x408b1d
-
Are you using any special parameters to setup the connection ?
-
No special parameters. Here is my code:
QString dbName = "mydb"; { QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", dbName); db.setHostName(databaseUrl); db.setPort(databasePort); db.setDatabaseName(databaseName); db.setUserName(databaseUsername); db.setPassword(databasePassword); // db.setConnectOptions("MYSQL_OPT_CONNECT_TIMEOUT=5"); if(db.open() == false) qDebug("Cannot access update database"); else { QSqlQuery query = QSqlQuery(db); ... } } QSqlDatabase::removeDatabase(dbName);
The crash is in open() with the same stack trace independently of using the timeout option or not. But I found something, that might help. If I turn off my wifi on my laptop, it crashes immediately. On the other hand, if the wifi is on, and I unplug the network cable from my router, it still crashes, but just after 20 seconds (which is not 5, as I would expect from the timeout option, but this might be another issue). In either case there was no connection to the remote mysql server. So there is a difference in behavior when there is a network interface and when no network interface exists.
-
Hi and welcome to devnet,
could be related to this?? https://bugreports.qt.io/browse/QTBUG-47452
-
@mcosta might be indeed
@szergejbubka It would be great if you could apply the following patch: https://codereview.qt-project.org/#/c/123488/ and test again
-
This patch solved the crash on Linux.
Thanks.
-
How can I apply this patch on windows?
Here is my stack trace:
0 load_defaults 0x5fff84c8 1 load_defaults 0x5fff8700 2 mysql_get_server_version 0x5ff8f60c 3 QMYSQLDriver::open C:/Qt/Qt5.5.0/5.5/mingw492_32/plugins/sqldrivers/qsqlmysqld.dll 1328 0x6ad85e6b 4 QSqlDatabase::open C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Sqld.dll 835 0xa87482e 5 FirstTimeWizard::checkDatabaseSettings firsttimewizard.cpp 318 0x42bff6 6 FirstTimeWizard::qt_static_metacall moc_firsttimewizard.cpp 99 0x43170d 7 QMetaObject::activate C:/Users/Thor/Pers/build-Mars-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/Qt5Cored.dll 3718 0x6b906d5f 8 QMetaObject::activate C:/Users/Thor/Pers/build-Mars-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/Qt5Cored.dll 3583 0x6b9066a4 9 QAbstractButton::clicked C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 303 0xb16616f 10 QAbstractButtonPrivate::emitClicked C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 534 0xaf26de9 11 QAbstractButtonPrivate::click C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 527 0xaf26d84 12 QAbstractButton::mouseReleaseEvent C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 1132 0xaf28083 13 QWidget::event C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 8665 0xae63f21 14 QAbstractButton::event C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 1089 0xaf27ef8 15 QPushButton::event C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 673 0xafb571e 16 QApplicationPrivate::notify_helper C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 3717 0xae2f3f1 17 QApplication::notify C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 3277 0xae2d513 18 QCoreApplication::notifyInternal C:/Users/Thor/Pers/build-Mars-Desktop_Qt_5_5_0_MinGW_32bit-Debug/debug/Qt5Cored.dll 965 0x6b8de86a 19 QCoreApplication::sendSpontaneousEvent C:/Qt/Qt5.5.0/5.5/mingw492_32/bin/Qt5Widgetsd.dll 227 0xb193ce5 ... <Mehr>
and here is the code:
QSqlDatabase datab = QSqlDatabase::addDatabase("QMYSQL", "test"); datab.setHostName(leHost->text()); datab.setPort(lePort->text().toInt()); datab.setDatabaseName("testname"); datab.setUserName(leUser->text().trimmed()); datab.setPassword(lePass->text()); if (datab.open()) { ... } else { ... }
-
It boils down to: get the sources of Qt 5 and apply the diff, then just build the plugin
-
Hi, same problem here.
I realized that when the program cannot find the database host it just crashes... when the program can find the database host but credentials are invalid qsqldatabase::open fails reporting "true" in every case, even with empty credentials...
When credentials are correct, it seems to work.The problem seems to be a bug with the QSqlDatabase::open, maybe the QSqlDriver::setOpen() or void QSqlDriver::setOpenError() are implemented in a wrong way in the last mysql plugin version (qt 5.5) in any older version I didn't face any problem.
So, for me it seems that they introduced a bug in QtMySql plugin on 5.5.
-
The bug has been reported, there's a patch waiting review. You can rebuild the MySQL plugin using the patch I linked to there:
@SGaist said:
@mcosta might be indeed
@szergejbubka It would be great if you could apply the following patch: https://codereview.qt-project.org/#/c/123488/ and test again