Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QSqlDatabase open crashes application
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase open crashes application

Scheduled Pinned Locked Moved Mobile and Embedded
22 Posts 6 Posters 10.7k 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
    #1

    Hello,
    got problem with QSqlDatabase:

    Code is simple:
    try{
    db.open()
    }
    catch(...){
    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?

    BR
    Tom

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

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

        Hi,

        What version of Qt ? On what OS ?

        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
          #4

          Qt 5.5
          Windows 8.1

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

            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 ?

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

              What is the 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
              • 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

                                          • Login

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