I’m developing an application using Qt5 on Ubuntu 20.04, and I need to connect to a PostgreSQL database. However, I’m encountering an issue where the QPSQL driver isn’t loaded. Here’s the error message I’m receiving:
Available drivers: ()
QSqlDatabase: QPSQL driver not loaded
I’ve verified that PostgreSQL is installed on my system, and I’ve included the necessary Qt SQL module. Despite this, it seems like the QPSQL driver is missing.
Here’s a brief overview of my setup:
Qt Version: 5.15
OS: Ubuntu 20.04
PostgreSQL Version: 9.6
I have already tried the following solutions without success:
Installed libqt5sql5-psql package using:
sudo apt-get install libqt5sql5-psql
Ensured that the plugins/sqldrivers directory contains the libqsqlpsql.so.
Set the QT_PLUGIN_PATH environment variable to point to the directory containing the SQL drivers.
export QT_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins
Below is a snippet of my code:
QCoreApplication::setLibraryPaths(QStringList() << "/usr/lib/x86_64-linux-gnu/qt5/plugins");
QStringList drivers = QSqlDatabase::drivers();
qDebug() << "Available drivers:" << drivers;
Installed libqt5sql5-psql
Ensured that the plugins/sqldrivers directory contains the libqsqlpsql.so.
Set the QT_PLUGIN_PATH