Site Overlay

What to do about “QPSQL driver not loaded”

If you created a PostgreSQL database object in your code with QtSql’s QSqlDatabase::addDatabase("PSQL"); your will sometimes get an Application Output like this:

What’s going on here is that the application tells your operating system that it is lacking the needed database client libraries. The solution is…

to make sure that your postgresql-client libraries are installed on your system:

… and to make sure that your Qt PostgreSQL plugin is installed. This is a bit more tricky, there is a libqt4-sql-psql and a libqt5-sql-psql plugin. As per the default Ubuntu 16.04 installation of Qt Creator, you should find libqsqlpsql.so under /usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers. In case it is not there, install it by:

Some folks recommend to explicitly register the plugin library by running ldd on the file. From my experience though, this is not necessary if the plugin was directly installed by apt-get as shown above.