Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Unable to compile SQL plugin



  • Good day.
    I wrote a small program to understand how Qt c ++ and SQL works.
    She writes to me:

    QSqlQuery::exec: database not open
    QSqlError("", "Driver not loaded", "Driver not loaded")
    ("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
    

    After reading the Internet, I found out that I needed a SQL plugin, I found this instruction https://doc.qt.io/qt-5/sql-driver.html#qpsql (Why are plugins not working out of the box? It doesn't matter.)
    Ok. I go to the folder ~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers
    Do "qmake -- PSQL_INCDIR=/usr/include/pgsql"
    Ok

    Running configuration tests...
    Done running configuration tests.
    
    Configure summary:
    
    Qt Sql Drivers:
      DB2 (IBM) .............................. no
      InterBase .............................. no
      MySql .................................. no
      OCI (Oracle) ........................... no
      ODBC ................................... no
      PostgreSQL ............................. yes
      SQLite2 ................................ no
      SQLite ................................. yes
        Using system provided SQLite ......... no
      TDS (Sybase) ........................... no
    
    Qt is now configured for building. Just run 'make'.
    Once everything is built, you must run 'make install'.
    Qt will be installed into '/usr'.
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    

    Do "make sub-psql"
    And I get

    cd psql/ && ( test -e Makefile || /usr/lib/qt5/bin/qmake -o Makefile /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/psql.pro PSQL_INCDIR=/usr/include/pgsql ) && make -f Makefile
    make[1]: вход в каталог «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
    g++ -c -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -O2 -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -Wno-stringop-overflow -Wno-deprecated-copy -Wno-redundant-move -Wno-format-overflow -Wno-init-list-lifetime -D_REENTRANT -fPIC -DQT_NO_JAVA_STYLE_ITERATORS -DQT_DEPRECATED_WARNINGS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8/QtCore -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I.moc -isystem /usr/include/postgresql -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o .obj/qsql_psql.o qsql_psql.cpp
    qsql_psql.cpp: In constructor ‘QPSQLDriverPrivate::QPSQLDriverPrivate()’:
    qsql_psql.cpp:152:68: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
      152 |     QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) {}
          |                                                                    ^
    In file included from qsql_psql.cpp:55:
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:66:5: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate()’
       66 |     QSqlDriverPrivate()
          |     ^~~~~~~~~~~~~~~~~
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:66:5: note:   candidate expects 0 arguments, 1 provided
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate(const QSqlDriverPrivate&)’
       61 | class QSqlDriverPrivate : public QObjectPrivate
          |       ^~~~~~~~~~~~~~~~~
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note:   no known conversion for argument 1 from ‘QSqlDriver::DbmsType’ to ‘const QSqlDriverPrivate&’
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriverPrivate&&)’
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note:   no known conversion for argument 1 from ‘QSqlDriver::DbmsType’ to ‘QSqlDriverPrivate&&’
    make[1]: *** [Makefile:384: .obj/qsql_psql.o] Error 1
    make[1]: выход из каталога «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
    make: *** [Makefile:45: sub-psql] Error 2
    

    What's happening? I just need to work with SQL, but that's all. If we open the sqldrivers.pro project using QtCreator, and try to compile, we get 3 errors:

    /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp:147: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
    /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp:147:73: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
      147 |     inline QSQLiteDriverPrivate() : QSqlDriverPrivate(QSqlDriver::SQLite) {}
          |                                                                         ^
    
    /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
    /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152:68: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
      152 |     QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) {}
          |                                                                    ^
    
    :-1: Error: [Makefile:845: .obj/qsql_sqlite.o] Error 1
    

    How do I get the plugin?
    I'm using communiti QtCreator, PostgreSQL 13.1 , Ubuntu 20.04


  • Lifetime Qt Champion

    @Anton1978 You forgot to mention what database you want to use actually?
    Looks like you want to use PostgreSQL. If this is the case there is no need to build anything, the plug-in is delivered with Qt (libqsqlpsql.so).
    For MySQL you have to build it by yourself because of MySQL license reasons.
    If the plug-in is not loaded then do this: set QT_DEBUG_PLUGINS env variable and then start your app. I guess PostgreSQL client library is not installed.



  • @jsulm Yes, use PostgreSQL. If i enter the command "sudo apt install postgresql-client-13"
    then the terminal writes "The most recent version of postgresql-client-13 package (13.1-1.pgdg20.04 + 1) is already installed.
    postgresql-client-13 is marked as manually installed."

    the output after export QT_DEBUG_PLUGINS = 1 is huge, even larger than the code of the program itself.
    Here it is, what would you advise to look for there?

    https://cloud.mail.ru/public/3tnm/Zn2pjp1qr


  • Lifetime Qt Champion

    You called the wrong qmake so the wrong headers are picked up. Call the qmake from your Qt version you're trying to compile the plugin for (I would guess it's 5.15 and not 5.12).
    Same problem here: https://forum.qt.io/topic/121095/issues-connecting-qt-to-mysql/9



  • tried to do so
    '~/Qt/5.15.2/gcc_64/bin/qmake -- PSQL_INCDIR=/usr/include/pgsql'
    Ok

    anton@home:~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers$ ~/Qt/5.15.2/gcc_64/bin/qmake -- PSQL_INCDIR=/usr/include/pgsql
    
    Running configuration tests...
    Done running configuration tests.
    
    Configure summary:
    
    Qt Sql Drivers:
      DB2 (IBM) .............................. no
      InterBase .............................. no
      MySql .................................. no
      OCI (Oracle) ........................... no
      ODBC ................................... no
      PostgreSQL ............................. yes
      SQLite2 ................................ no
      SQLite ................................. yes
        Using system provided SQLite ......... no
      TDS (Sybase) ........................... no
    
    Qt is now configured for building. Just run 'make'.
    Once everything is built, you must run 'make install'.
    Qt will be installed into '/home/anton/Qt/5.15.2/gcc_64'.
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    

    Ok, do it 'make sub-psql'
    And...

    anton@home:~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers$ make sub-psql
    cd psql/ && ( test -e Makefile || /home/anton/Qt/5.15.2/gcc_64/bin/qmake -o Makefile /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/psql.pro ) && make -f Makefile
    make[1]: вход в каталог «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
    g++ -c -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -O2 -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -Wno-stringop-overflow -Wno-deprecated-copy -Wno-redundant-move -Wno-format-overflow -Wno-init-list-lifetime -D_REENTRANT -fPIC -DQT_NO_JAVA_STYLE_ITERATORS -DQT_DEPRECATED_WARNINGS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8/QtCore -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I.moc -isystem /usr/include/postgresql -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o .obj/qsql_psql.o qsql_psql.cpp
    qsql_psql.cpp: In constructor ‘QPSQLDriverPrivate::QPSQLDriverPrivate()’:
    qsql_psql.cpp:152:68: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
      152 |     QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) {}
          |                                                                    ^
    In file included from qsql_psql.cpp:55:
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:66:5: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate()’
       66 |     QSqlDriverPrivate()
          |     ^~~~~~~~~~~~~~~~~
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:66:5: note:   candidate expects 0 arguments, 1 provided
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate(const QSqlDriverPrivate&)’
       61 | class QSqlDriverPrivate : public QObjectPrivate
          |       ^~~~~~~~~~~~~~~~~
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note:   no known conversion for argument 1 from ‘QSqlDriver::DbmsType’ to ‘const QSqlDriverPrivate&’
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriverPrivate&&)’
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note:   no known conversion for argument 1 from ‘QSqlDriver::DbmsType’ to ‘QSqlDriverPrivate&&’
    make[1]: *** [Makefile:384: .obj/qsql_psql.o] Ошибка 1
    make[1]: выход из каталога «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
    make: *** [Makefile:45: sub-psql] Ошибка 2
    

    it looks like mockery


  • Lifetime Qt Champion

    @Anton1978 said in Unable to compile SQL plugin:

    /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8

    Still using the wrong include paths. Make sure to start with a clean source dir.



  • I really don't understand why this is happening? I am explicitly specifying which qmake to use - '~/Qt/5.15.2/gcc_64/bin/qmake'
    Even if I write like this
    ~/Qt/5.15.2/gcc_64/bin/qmake -- PSQL_INCDIR=~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers
    the result does not change
    why is the file used
    /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h

    I think me need some rest



  • Another interesting point, if you open the SQLPlagin project in QTCreator, you can see that the sources with errors
    /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/sqldrivers.pro
    have 3 errors

    /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152: error: no matching constructor for initialization of 'QSqlDriverPrivate' 
    
    :-1: error: [Makefile:845: .obj/qsql_sqlite.o] Error 1
    
    /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
    /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152:68: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
      152 |     QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) {}
    

    He writes to me about these errors when using make.
    But for others it compiles.
    Some kind of mysticism.


  • Lifetime Qt Champion

    Again: start with a clean source dir and call the correct qmake.



  • It is not necessary to compile the plugin but it is only necessary to install the client, in the case of Ubuntu it is enough with:

    sudo apt-get install libpq-dev
    


  • @eyllanesc
    It's installed, everything doesn't work


  • Lifetime Qt Champion

    Hi,

    As @Christian-Ehrlicher wrote, you have to clean the sources before starting fresh. There are also hidden files in the folder that you need to remove (you can find that here).

    If you want to be on the safe side, you can even to an out of source build.



  • @Anton1978 It is very strange since I have tested an example in GH actions and it works correctly for me, on the other hand if you want to compile it recommends you delete the files generated by your incorrect execution. You can also follow my answer in SO:https://stackoverflow.com/a/65568190/6622587



  • @eyllanesc said in Unable to compile SQL plugin:

    @Anton1978 It is very strange since I have tested an example in GH actions and it works correctly for me, on the other hand if you want to compile it recommends you delete the files generated by your incorrect execution. You can also follow my answer in SO:https://stackoverflow.com/a/65568190/6622587

    This my question too)). The second day I am at war with this plugin.
    Thanks for prompting me to git this plugin, it really helped, now it remains to figure out how to connect the compiled plugin to my QtCreator.


  • Lifetime Qt Champion

    @Anton1978 said in Unable to compile SQL plugin:

    how to connect the compiled plugin to my QtCreator

    You only need to call "make install" after make, then it should work.

    It would be interesting to know why the preinstalled plug-in doesn't work. To do so set QT_DEBUG_PLUGINS=1 before starting your app. Then you should see what is happening.


Log in to reply