QSqlDatabase open crashes application

  • Hello,
    got problem with QSqlDatabase:

    Code is simple:
    std::cout << "Something is wrong";

    Of corse I got db fully configured and is everything ok if I got internet connection (remote database) but if not the application carshes. No exception no nothing?

    Does anybody know where is the problem?


  • If I change host name to non valid it also crashes...

    Db config looks ike:

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName( "host" );
    db.setDatabaseName( "dbName" );
    db.setUserName( "username" );
    db.setPassword( "password" );

  • Lifetime Qt Champion


    What version of Qt ? On what OS ?

  • Qt 5.5
    Windows 8.1

  • As I checked in debug mode got segmentation fault from open() function.

    Could I do something with that or it's a bug and I have to find different way to work with databases ?

  • Lifetime Qt Champion

    What is the stack trace ?

  • 0 QMYSQLDriver::open qsql_mysql.cpp 1320 0x6ad85e22
    1 QSqlDatabase::open C:/QtNew/5.5/mingw492_32/bin/Qt5Sqld.dll 835 0x6794482e
    2 main main.cpp 21 0x401756

    Crashes on line:
    mysql_set_character_set(d->mysql, "utf8");

  • Lifetime Qt Champion

    What version of MySQL do you have installed ?

  • +-------------------------+------------------------------+
    | Variable_name | Value
    | innodb_version | 1.1.8
    | protocol_version | 10
    | slave_type_conversions
    | version | 5.5.15
    | version_comment | MySQL Community Server (GPL)
    | version_compile_machine | x86
    | version_compile_os | Win32

    I have to mention that use of 32 bit MySQL on 64 bit machine is determinated by using mingw32. Otherwise I couldn't compile mysql driver.

  • Any progress? I have this issue too on Linux 64bit with Qt 5.5. With Qt 5.4.2 it works as expected, open() returns false. How could I help in fixing or finding a solution/workaround?

  • I am facing the same issue with Windows 7 64bit, MySQL 5.6 32bit, Qt 5.5 mingw. With Qt 5.4.1 it worked without any problem.

  • Lifetime Qt Champion

    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	

  • Lifetime Qt Champion

    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.setConnectOptions("MYSQL_OPT_CONNECT_TIMEOUT=5");
            if(db.open() == false)
                qDebug("Cannot access update database");
            else {
                QSqlQuery query = QSqlQuery(db);

    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

  • Lifetime Qt Champion

    @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.


  • 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");
        if (datab.open()) {

  • Lifetime Qt Champion

    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.

  • Lifetime Qt Champion

    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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.