简体   繁体   中英

How get the Qt PostgreSQL plugin in ubuntu?

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.

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?

I lost hope, what else can I do?

Its log after "export QT_DEBUG_PLUGINS = 1" https://cloud.mail.ru/public/3tnm/Zn2pjp1qr

I installed Qt in the 'home/myname/Qt' folder But as I see the log now, there is an independent folder /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/ I didn't create it. Now I run make in the '~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers' folder And got new errors:

anton@home:~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers$ make sub-psql
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] Ошибка 1
make[1]: выход из каталога «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
make: *** [Makefile:45: sub-psql] Ошибка 2

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) {}

If you want to use the PostgreSQL plugin in Ubuntu, just install the client as Qt provides the plugin:

sudo apt-get install libpq-dev

On the other hand, if you want to compile the plugin (which in general is unnecessary) then you must follow the following steps:

sudo apt-get install libpq-dev
git clone -b 5.15.2 https://code.qt.io/qt/qtbase.git
cd qtbase/src/plugins/sqldrivers
~/Qt/5.15.2/gcc_64/bin/qmake -- PSQL_INCDIR=/usr/include/pgsql
make sub-psql
make install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM