Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QMYSQLDriver
Forum Updated to NodeBB v4.3 + New Features

Problem with QMYSQLDriver

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 3 Posters 6.3k 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.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 26 Jan 2018, 19:13 last edited by
    #4

    Hi
    Did you build your own version of it ?
    https://forum.qt.io/topic/59449/qsqldatabase-qmysql-driver-not-loaded-build-mysql-plugin

    You should try
    ldd to libqsqlmysql.so
    and see if anything missing.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DoubleC122
      wrote on 26 Jan 2018, 19:24 last edited by
      #5

      Oh yes, I almost forgot about that. I tried to build it once, but I had problems with a certain library. Now I'm sure I have everything I need, so when I run qmake I don't get any message back (I'm not sure if that is a good sign). After that I run make, but I get 'make: Nothing to be done for 'first'. '.

      M 1 Reply Last reply 26 Jan 2018, 19:26
      0
      • D DoubleC122
        26 Jan 2018, 19:24

        Oh yes, I almost forgot about that. I tried to build it once, but I had problems with a certain library. Now I'm sure I have everything I need, so when I run qmake I don't get any message back (I'm not sure if that is a good sign). After that I run make, but I get 'make: Nothing to be done for 'first'. '.

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 26 Jan 2018, 19:26 last edited by mrjj
        #6

        @DoubleC122
        But it does build the actual .SO file?
        Also what does
        ldd libqsqlmysql.so
        lists ?
        any missing so files?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DoubleC122
          wrote on 26 Jan 2018, 19:30 last edited by
          #7

          So ldd libqsqlmysql.so returns this:

              linux-vdso.so.1 =>  (0x00007ffe14188000)
              libQt5Sql.so.5 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007fe6c35e1000)
              libQt5Core.so.5 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007fe6c2ea7000)
              libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe6c2c88000)
              libmysqlclient.so.18 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 (0x00007fe6c273d000)
              libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe6c23b7000)
              libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe6c2061000)
              libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe6c1e4a000)
              libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe6c1a6a000)
              libicui18n.so.56 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.56 (0x00007fe6c15d1000)
              libicuuc.so.56 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.56 (0x00007fe6c1219000)
              libicudata.so.56 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.56 (0x00007fe6bf836000)
              libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe6bf619000)
              libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe6bf415000)
              libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fe6bf213000)
              libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fe6beeff000)
              /lib64/ld-linux-x86-64.so.2 (0x00007fe6c3a3b000)
              librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe6becf7000)
              libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fe6bea85000)
          

          Apparently there is none missing.

          M 1 Reply Last reply 26 Jan 2018, 19:35
          0
          • D DoubleC122
            26 Jan 2018, 19:30

            So ldd libqsqlmysql.so returns this:

                linux-vdso.so.1 =>  (0x00007ffe14188000)
                libQt5Sql.so.5 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007fe6c35e1000)
                libQt5Core.so.5 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007fe6c2ea7000)
                libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe6c2c88000)
                libmysqlclient.so.18 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 (0x00007fe6c273d000)
                libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe6c23b7000)
                libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe6c2061000)
                libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe6c1e4a000)
                libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe6c1a6a000)
                libicui18n.so.56 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.56 (0x00007fe6c15d1000)
                libicuuc.so.56 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.56 (0x00007fe6c1219000)
                libicudata.so.56 => /home/catalin/Qt/5.9.1/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.56 (0x00007fe6bf836000)
                libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe6bf619000)
                libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe6bf415000)
                libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fe6bf213000)
                libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fe6beeff000)
                /lib64/ld-linux-x86-64.so.2 (0x00007fe6c3a3b000)
                librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe6becf7000)
                libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fe6bea85000)
            

            Apparently there is none missing.

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 26 Jan 2018, 19:35 last edited by
            #8

            Hi
            Nope it looks good.
            libmysqlclient.so.18 is a bit newer than i normally see but should work fine, i assume.

            Also the error
            "QMYSQLDriver was not declared in this scope"

            does not sound the normal errors . ( driver not loaded )

            Do it say it for your Qt code ?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DoubleC122
              wrote on 26 Jan 2018, 19:47 last edited by DoubleC122
              #9

              Ok, I'll try to get into a bit more detail. Even though it shouldnt be a major factor I guess, I have a QtWidget project and in the source file, in the constructor of the mainwindow, I typed QMYSQLDriver *drv = new QMYSQLDriver(con);. The major error is that one, but I also get "drv was not declared in this scope" (which seems fine, since it doesnt even recognize QMYSQLDriver), and also "expected type-specifier before QMYSQLDriver". Not sure how much of this is helping. Also, regarding the .so file generation, pardon my ignorance, but I'm not very accustomed with makefiles and such. The .so file should be generated in the very same file? Because if so, I don't have any .so right there.

              M 1 Reply Last reply 26 Jan 2018, 19:57
              0
              • D DoubleC122
                26 Jan 2018, 19:47

                Ok, I'll try to get into a bit more detail. Even though it shouldnt be a major factor I guess, I have a QtWidget project and in the source file, in the constructor of the mainwindow, I typed QMYSQLDriver *drv = new QMYSQLDriver(con);. The major error is that one, but I also get "drv was not declared in this scope" (which seems fine, since it doesnt even recognize QMYSQLDriver), and also "expected type-specifier before QMYSQLDriver". Not sure how much of this is helping. Also, regarding the .so file generation, pardon my ignorance, but I'm not very accustomed with makefiles and such. The .so file should be generated in the very same file? Because if so, I don't have any .so right there.

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 26 Jan 2018, 19:57 last edited by
                #10

                Hi
                Normally it build in same folder or just a folder above it.

                Im wondering if your use case is different from normal use.
                Normally you dont new a driver yourself, but uses it via the Databaseclass
                something like. ( not tested as i dont have mysql installed here)

                #include "mainwindow.h"
                #include <QApplication>
                #include <QWidget>
                #include <QtSql>
                #include <QDebug>
                #include "qsqldriver.h"
                
                
                int main(int argc, char *argv[])
                {
                QApplication a(argc, argv);
                
                QString servername = "LOCALHOST//QMYSQL";
                QString dbname = "test";
                QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                
                db.setConnectOptions();
                
                QString dsn = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername) .arg(dbname);
                
                db.setDatabaseName(dsn);
                
                if(db.open()){
                    qDebug() << "Opened";
                    db.close();
                }
                else{
                    qDebug() << "Error =" << db.lastError().text();
                    qDebug ( )  <<  QSqlDatabase :: drivers ( );
                }
                
                MainWindow w;
                
                w.show();
                
                return a.exec();
                }
                
                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DoubleC122
                  wrote on 26 Jan 2018, 20:11 last edited by
                  #11

                  Well yes if I use QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); it doesn't return any error. But what I wanted to do actually is doing what I saw in the QSqlDatabase help document in Qt. There it said I could use another driver (in this case the mySqlConnector) and use it through the QMYSQLDriver class. In the help document I followed the example (of course I used mySQL, not Postgres):

                  #include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"

                  PGconn *con = PQconnectdb("host=server user=bart password=simpson dbname=springfield");
                  QPSQLDriver *drv = new QPSQLDriver(con);
                  QSqlDatabase db = QSqlDatabase::addDatabase(drv); // becomes the new default connection
                  QSqlQuery query;
                  query.exec("SELECT NAME, ID FROM STAFF");
                  ...

                  M 1 Reply Last reply 27 Jan 2018, 11:31
                  0
                  • D DoubleC122
                    26 Jan 2018, 20:11

                    Well yes if I use QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); it doesn't return any error. But what I wanted to do actually is doing what I saw in the QSqlDatabase help document in Qt. There it said I could use another driver (in this case the mySqlConnector) and use it through the QMYSQLDriver class. In the help document I followed the example (of course I used mySQL, not Postgres):

                    #include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"

                    PGconn *con = PQconnectdb("host=server user=bart password=simpson dbname=springfield");
                    QPSQLDriver *drv = new QPSQLDriver(con);
                    QSqlDatabase db = QSqlDatabase::addDatabase(drv); // becomes the new default connection
                    QSqlQuery query;
                    query.exec("SELECT NAME, ID FROM STAFF");
                    ...

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 27 Jan 2018, 11:31 last edited by
                    #12

                    Hi
                    Ahhh. never tried that :)

                    it goes
                    #include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"
                    QPSQLDriver *drv = new QPSQLDriver(con);

                    So I assumed you tried with
                    #include "qtdir\qtbase\src\plugins\sqldrivers\mysql\qsql_mysql.cpp"
                    QMYSQLDriver

                    and got errors ?

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DoubleC122
                      wrote on 27 Jan 2018, 14:28 last edited by
                      #13

                      Yes indeed, I followed that example but for QMYSQL. I stopped right after instantiating the drv pointer because it was not recognizing the QMYSQLDriver.

                      M 1 Reply Last reply 27 Jan 2018, 14:29
                      0
                      • D DoubleC122
                        27 Jan 2018, 14:28

                        Yes indeed, I followed that example but for QMYSQL. I stopped right after instantiating the drv pointer because it was not recognizing the QMYSQLDriver.

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 27 Jan 2018, 14:29 last edited by
                        #14

                        @DoubleC122
                        and you changed the path to points to the mysql. cpp file ?
                        (the class is defined there)

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          DoubleC122
                          wrote on 27 Jan 2018, 14:34 last edited by
                          #15

                          Yes, I changed everything there to go as it should. But apparently it didnt. I included just like this: #include "/home/catalin/Qt/5.9.1/Src/qtbase/src/plugins/sqldrivers/mysql/qsql_mysql.cpp". And Qt recognizes it. I also checked if there was actually that .cpp file there just to be sure, even if it is redundant to do so.

                          M 1 Reply Last reply 27 Jan 2018, 14:39
                          0
                          • D DoubleC122
                            27 Jan 2018, 14:34

                            Yes, I changed everything there to go as it should. But apparently it didnt. I included just like this: #include "/home/catalin/Qt/5.9.1/Src/qtbase/src/plugins/sqldrivers/mysql/qsql_mysql.cpp". And Qt recognizes it. I also checked if there was actually that .cpp file there just to be sure, even if it is redundant to do so.

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 27 Jan 2018, 14:39 last edited by
                            #16

                            @DoubleC122
                            and this .cpp should include the .h file and the object should be known. hmm.
                            Its not inside namespace or anything that would prevent it from knowing type ?

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              DoubleC122
                              wrote on 27 Jan 2018, 14:49 last edited by DoubleC122
                              #17

                              Not really, I tried using that even in a simple non Qt project, to see if at least that would do, but it didn't. For instance, in a simple blank project, I include whatever I need, plus the mysql connector header files and the path to the .cpp. Then, in main, I have just these lines:

                              sql::Driver *driver;
                              sql::Connection *con;
                              
                              driver = get_driver_instance();
                              con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
                              
                              QMYSQLDriver *drv = new QMYSQLDriver(con);
                              

                              And it says that #include <QtSql/private/qsqldriver_p.h> and #include <QtSql/private/qsqlresult_p.h> 'no such file or directory'. These are included in the qsql_mysql.cpp file. I certainly have those headers, since I looked a thousand times for them. If I try to include them 'manually', pretty much as I did for the qsql_mysql.cpp, it works, but I don't feel like it's a good idea also because then it moves on the other headers inside those I included and says the same error. Maybe the headers in qsql_mysql.cpp point somewhere else than where I looked for, I really have no idea.

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 27 Jan 2018, 14:51 last edited by
                                #18

                                Hi
                                I wonder if you need something like (in .pro file)
                                QT += gui-private
                                as we do for other private headers.
                                (looking for right name)

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  DoubleC122
                                  wrote on 27 Jan 2018, 14:57 last edited by DoubleC122
                                  #19

                                  @mrjj said in Problem with QMYSQLDriver:

                                  gui-private

                                  Unfortunately it doesnt change anything. Actually, I saw something else. If I just include the .cpp file without writing anything else, it shows me the header errors. Before, it showed me that the QMYSQLDriver was not declared in this scope, now if I just include the .cpp file, it shows me this error, which it didn't before.

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 27 Jan 2018, 21:11 last edited by
                                    #20

                                    Hi,

                                    That would be sql-private. But from a quick look the plugin headers are not exported.

                                    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
                                    1
                                    • M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 28 Jan 2018, 08:51 last edited by
                                      #21

                                      So its not really possible to use a stand alone driver as the helps shows ?
                                      or it does only apply to the QPSQLDriver ?

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        DoubleC122
                                        wrote on 28 Jan 2018, 12:20 last edited by
                                        #22

                                        Frankly now that I spent so much time on this error, I think I could use the normal QSqlDatabase class without using the connector from mysql. From what I saw it's similar to the QMYSQLDriver in the sense that I need to specify what database I want to use just like what I wanted to do before, but instead I don't use any other non qt driver in between, and of course mysql is in the list of supported connection databases so it's really good.

                                        1 Reply Last reply
                                        1

                                        13/22

                                        27 Jan 2018, 14:28

                                        • Login

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