Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QSqlDatabase open crashes application
Qt 6.12 LTS is out! See what's new in the release blog

QSqlDatabase open crashes application

Scheduled Pinned Locked Moved Mobile and Embedded
22 Posts 6 Posters 23.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kaluss
    wrote on last edited by
    #7

    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");

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #8

      What version of MySQL do you have installed ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kaluss
        wrote on last edited by
        #9

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          szergejbubka
          wrote on last edited by szergejbubka
          #10

          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?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SebastianS
            wrote on last edited by
            #11

            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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #12

              Same stack trace ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                szergejbubka
                wrote on last edited by
                #13

                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	
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  Are you using any special parameters to setup the connection ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    szergejbubka
                    wrote on last edited by
                    #15

                    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.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mcosta
                      wrote on last edited by
                      #16

                      Hi and welcome to devnet,

                      could be related to this?? https://bugreports.qt.io/browse/QTBUG-47452

                      Once your problem is solved don't forget to:

                      • Mark the thread as SOLVED using the Topic Tool menu
                      • Vote up the answer(s) that helped you to solve the issue

                      You can embed images using (http://imgur.com/) or (http://postimage.org/)

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        @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

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          szergejbubka
                          wrote on last edited by
                          #18

                          This patch solved the crash on Linux.

                          Thanks.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SebastianS
                            wrote on last edited by
                            #19

                            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
                                {
                                    ...
                                }
                            
                            
                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #20

                              It boils down to: get the sources of Qt 5 and apply the diff, then just build the plugin

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #21

                                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.

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #22

                                  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

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt
                                  • Unsolved