QSqlDatabase: QPSQL driver not loaded
-
Qt 5.10.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160406 (Red Hat 5.3.1-6)) on "xcb"
OS: Ubuntu 17.10 [linux version 4.13.0-39-generic]This is a question that has been asked many times before, but I can’t find an answer that works for me, I have managed to get it working myself with previous versions of Qt, but I guess I am missing something obvious.
I am trying to use PostgreSQL and having problems getting it to run, I’m getting the following error messages:
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3Having had problems setting up database drivers before I have kept a script to hand which I’ve modified to suit the version when I required it.
I have tried the script below, both with and without the ‘make install’ line being included.
#!/bin/bash sudo apt-get install postgresql-client libpq-dev pgadmin3 postgresql-doc-9.6 WorkingDir="/home/mike/software/Qt/5.10.1/Src/qtbase/src/plugins/sqldrivers/psql/" QTDIR=/home/mike/software/Qt/5.10.1/gcc_64/ export QTDIR PATH="$PATH:$QTDIR/bin" export PATH QMAKE=/home/mike/software/Qt/5.10.1/gcc_64/bin export QMAKE cd "/home/mike/software/Qt/5.10.1/Src/qtbase/src/plugins/sqldrivers/" /home/mike/software/Qt/5.10.1/gcc_64/bin/qmake sqldrivers.pro cd $WorkingDir /home/mike/software/Qt/5.10.1/gcc_64/bin/qmake "INCLUDEPATH+=/usr/include/postgresql" "LIBS+=-L/usr/lib/postgresql -lpq" psql.pro read -p "1. Press [Enter] to continue..." make #cd $WorkingDir # sudo make install
My database server works correctly and I can create and access databases using the command line locally (using SSH) and remotely using PG Admin III on my development machine.
The output from the script is below:
Reading package lists... Done Building dependency tree Reading state information... Done pgadmin3 is already the newest version (1.22.2-1). libpq-dev is already the newest version (9.6.8-0ubuntu0.17.10). postgresql-client is already the newest version (9.6+184ubuntu1.1). postgresql-doc-9.6 is already the newest version (9.6.8-0ubuntu0.17.10). 0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade. Running configuration tests... Done running configuration tests. Configure summary: Qt Sql: 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, Qt is installed. You should NOT run 'make install'. Note that this build cannot be deployed to other machines or devices. Prior to reconfiguration, make sure you remove any leftovers from the previous build.
The Folder below holds the following files:
/home/mike/software/Qt/5.10.1/gcc_64/plugins/sqldrivers/
libqsqlite.so
libqsqlmysql.so
libqsqlpsql.soI also tried the commands below that I found on the Qt website.
cd /home/mike/software/Qt/5.10.1/Src/qtbase/src/plugins/sqldrivers qmake -- PSQL_INCDIR=/usr/include/pgsql make sub-psql
I have used SQLite recently without any problems.
The contents of my .pro file, slimmed down to reduce space are below:
QT += core gui network printsupport sql help CONFIG += c++11 QTPLUGIN += QPSQL QT_DEBUG_PLUGINS=1 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Cognitive_Companion TEMPLATE = app ParentDirectory = "/home/mike/Code_Builds/$$TARGET" RCC_DIR = "$$ParentDirectory/Build/RCCFiles" UI_DIR = "$$ParentDirectory/Build/UICFiles" MOC_DIR = "$$ParentDirectory/Build/MOCFiles" OBJECTS_DIR = "$$ParentDirectory/Build/ObjFiles" CONFIG(debug, debug|release) { DESTDIR = "$$ParentDirectory/debug" } CONFIG(release, debug|release) { DESTDIR = "$$ParentDirectory/release" } RESOURCES += \ icons.qrc \ lists.qrc \ images.qrc INCLUDEPATH += "/usr/include/postgresql/" LIBS += "/home/mike/software/Qt/5.10.1/gcc_64/plugins/sqldrivers/libqsqlpsql.so"
In the past (previous projects, with earlier versions of everything), I have managed to get this working and not had the LIBS and INCLUDEPATH elements, but I tried them incase.
The lines from my database class constructor are below:
m_DB = QSqlDatabase::addDatabase("QPSQL"); m_DB.setHostName("***.***.**.***"); m_DB.setDatabaseName("Cognitive_Companion"); m_DB.setUserName("*****"); m_DB.setPassword("*********");
The error happens when the object is constructed, because it can find the driver.
I search these forums have spent a lot of time googling and there are some may answers out there that don’t make any difference and often are very old.
Any assistance would be appreciated.
-
I have managed to get it working on my Laptop, which is virtually the same software, built at the same time. I just run my BASH script and it worked.
I then uninstalled and re-installed Qt on my Desktop, but that didn't make any difference. This makes me think that I have some files remaining that are causing a problem with this. A message after the install with the script says:
Prior to reconfiguration, make sure you remove any leftovers from
the previous build.Where would these files be so that I can remove them?
Thanks.
-
Hi,
To remove everything you should call make distclean. Also, look for files like .qmake.*.
If you'd rather avoid having to clean up the sources, you should consider doing out of source builds, that way you can just nuke the build folder and start over.
-
I upgraded from Kubuntu 17.10 to 18.4, using the update the existing installation approach. I wasn't finding 17.10 very stable on my desktop machine, though it was on the Laptop.
I tried it again and that didn't solve the problem, so I uninstalled Qt, deleted the configuration files from .config folder and then reinstalled and now I have it working.
Thanks.