[SOLVED] Qt 5.5.1 / PostgreSQL Driver / Centos 7.0 : QPSQL driver not loaded
-
I have installed Qt 5.5.1 in my Centos 7.1 (64bit). This is my Qt path: /usr/local/qt
Looking for database drivers, I noticed that my system has several, including Postgres support:ls /usr/local/qt/5.5/gcc_64/plugins/sqldrivers libqsqlite.so libqsqlmysql.so libqsqlpsql.so
But if I try to run a "hello world" application trying to load the Postgres driver, I got the error message: "QPSQL driver not loaded"
In fact, when I try to print the list of available drivers I got an empty list:qDebug() << "DB Drivers: " << QSqlDatabase::drivers();
So, I decided to compile the driver by myself, then, I installed Postgres dependencies (libs/headers) and downloaded the Qt (5.5.1) source code:
wget http://download.qt.io/official_releases/qt/5.5/5.5.1/single/qt-everywhere-opensource-src-5.5.1.tar.gz tar xvfz qt-everywhere-opensource-src-5.5.1.tar.gz
Then I compiled the Postgres driver:
cd qt-everywhere-opensource-src-5.5.1/qtbase/src/plugins/sqldrivers/psql qmake "INCLUDEPATH+=/usr/include/pgsql" "LIBS+=-L/lib64 -lpq" psql.pro make /usr/local/qt/5.5/gcc_64/bin/moc -DQT_NO_MTDEV -DQT_NO_LIBUDEV -DQT_NO_TSLIB -DQT_NO_LIBINPUT -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/home/xtingray/tmp/qt-everywhere-opensource-src-5.5.1/qtbase/mkspecs/linux-g++ -I/home/xtingray/tmp/qt-everywhere-opensource-src-5.5.1/qtbase/src/plugins/sqldrivers/psql -I/usr/include/pgsql -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1/QtCore -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1/QtSql -I/usr/local/qt/5.5/gcc_64/include -I/usr/local/qt/5.5/gcc_64/include/QtSql -I/usr/local/qt/5.5/gcc_64/include/QtCore main.cpp -o .moc/main.moc g++ -c -pipe -O2 -fvisibility=hidden -fvisibility-inlines-hidden -std=c++0x -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DQT_NO_MTDEV -DQT_NO_LIBUDEV -DQT_NO_TSLIB -DQT_NO_LIBINPUT -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. -I/usr/include/pgsql -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1/QtCore -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1/QtSql -I/usr/local/qt/5.5/gcc_64/include -I/usr/local/qt/5.5/gcc_64/include/QtSql -I/usr/local/qt/5.5/gcc_64/include/QtCore -I.moc -I../../../../mkspecs/linux-g++ -o .obj/main.o main.cpp g++ -c -pipe -O2 -fvisibility=hidden -fvisibility-inlines-hidden -std=c++0x -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DQT_NO_MTDEV -DQT_NO_LIBUDEV -DQT_NO_TSLIB -DQT_NO_LIBINPUT -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. -I/usr/include/pgsql -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1/QtCore -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1/QtSql -I/usr/local/qt/5.5/gcc_64/include -I/usr/local/qt/5.5/gcc_64/include/QtSql -I/usr/local/qt/5.5/gcc_64/include/QtCore -I.moc -I../../../../mkspecs/linux-g++ -o .obj/qsql_psql.o ../../../sql/drivers/psql/qsql_psql.cpp In file included from /usr/local/qt/5.5/gcc_64/include/QtCore/qregexp.h:41:0, from /usr/local/qt/5.5/gcc_64/include/QtCore/qstringlist.h:40, from /usr/local/qt/5.5/gcc_64/include/QtCore/qlist.h:1026, from /usr/local/qt/5.5/gcc_64/include/QtCore/qvariant.h:39, from /usr/local/qt/5.5/gcc_64/include/QtSql/qsqlresult.h:37, from ../../../sql/drivers/psql/qsql_psql_p.h:48, from ../../../sql/drivers/psql/qsql_psql.cpp:34: /usr/local/qt/5.5/gcc_64/include/QtCore/qstring.h: In member function ‘virtual QVariant QPSQLResult::data(int)’: /usr/local/qt/5.5/gcc_64/include/QtCore/qstring.h:969:47: warning: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Wstrict-overflow] { return i < s.d->size ? s.d->data()[i] : 0; } ^ /usr/local/qt/5.5/gcc_64/bin/moc -DQT_NO_MTDEV -DQT_NO_LIBUDEV -DQT_NO_TSLIB -DQT_NO_LIBINPUT -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/home/xtingray/tmp/qt-everywhere-opensource-src-5.5.1/qtbase/mkspecs/linux-g++ -I/home/xtingray/tmp/qt-everywhere-opensource-src-5.5.1/qtbase/src/plugins/sqldrivers/psql -I/usr/include/pgsql -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1/QtCore -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1/QtSql -I/usr/local/qt/5.5/gcc_64/include -I/usr/local/qt/5.5/gcc_64/include/QtSql -I/usr/local/qt/5.5/gcc_64/include/QtCore ../../../sql/drivers/psql/qsql_psql_p.h -o .moc/moc_qsql_psql_p.cpp g++ -c -pipe -O2 -fvisibility=hidden -fvisibility-inlines-hidden -std=c++0x -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DQT_NO_MTDEV -DQT_NO_LIBUDEV -DQT_NO_TSLIB -DQT_NO_LIBINPUT -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. -I/usr/include/pgsql -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtCore/5.5.1/QtCore -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1 -I/usr/local/qt/5.5/gcc_64/include/QtSql/5.5.1/QtSql -I/usr/local/qt/5.5/gcc_64/include -I/usr/local/qt/5.5/gcc_64/include/QtSql -I/usr/local/qt/5.5/gcc_64/include/QtCore -I.moc -I../../../../mkspecs/linux-g++ -o .obj/moc_qsql_psql_p.o .moc/moc_qsql_psql_p.cpp rm -f libqsqlpsql.so g++ -Wl,--no-undefined -Wl,-O1 -Wl,--enable-new-dtags -Wl,-rpath,/home/xtingray/Qt/5.5/gcc_64 -Wl,-rpath,/home/user/Qt/5.5/gcc_64 -Wl,-rpath,/home/user/Qt/5.5/gcc_64/lib -shared -o libqsqlpsql.so .obj/main.o .obj/qsql_psql.o .obj/moc_qsql_psql_p.o -L/lib64 -lpq -L/usr/local/qt/5.5/gcc_64/lib -lQt5Sql -lQt5Core -lpthread mv -f libqsqlpsql.so ../../../../plugins/sqldrivers/
And finally, I installed the driver:
make install install -m 755 -p ../../../../plugins/sqldrivers/libqsqlpsql.so /usr/local/qt/5.5/gcc_64/plugins/sqldrivers/libqsqlpsql.so strip --strip-unneeded /usr/local/qt/5.5/gcc_64/plugins/sqldrivers/libqsqlpsql.so install -m 644 -p /home/xtingray/tmp/qt-everywhere-opensource-src-5.5.1/qtbase/lib/cmake/Qt5Sql/Qt5Sql_QPSQLDriverPlugin.cmake /usr/local/qt/5.5/gcc_64/lib/cmake/Qt5Sql/
But when I compile and run my "hello world" program again, I keep getting the same error message: QPSQL driver not loaded
Any hint about what I am doing wrong?
-
Hi,
You should start your application with the QT_DEBUG_PLUGINS environment variable set to 1 that should give you some additional hints about what is going on.
-
@SGaist That's it! Thank you!
export QT_DEBUG_PLUGINS=1 ./sample ... QFactoryLoader::QFactoryLoader() checking directory path "/home/sample/bin/sqldrivers" ... QFactoryLoader::QFactoryLoader() looking at "/home/sample/bin/sqldrivers/libqsqlpsql.so" ...
I had to create the folder "sqldrivers" inside my "bin" directory and put the driver there (libqsqlpsql.so), then I could run my code successfully! :)
-
So you were running it outside Qt Creator ! :)
-
There are several possibilities setting RPATH in your application and dependencies would be the cleanest. Unless you make use of your distribution provided Qt.
By the way, no need to modify the title anymore, you can use the "Topic Tool" button to mark the thread as solved :)