QPSQL driver cannot be loaded
-
Hello,
I am combing through the forums and information on the internet to find a solution.
I am trying to run the following code on my Windows 11 PC with Qt 5.15 Mingw 32 Bit compiler.m_db = QSqlDatabase::addDatabase("QPSQL"); m_db.setHostName("192.168.112.70"); m_db.setDatabaseName("myDB"); m_db.setUserName("user"); m_db.setPassword("pwd"); qDebug() << "Available Drivers: " << QSqlDatabase::drivers(); if (!m_db.open()) { qDebug() << "Failed to connect to database:" << m_db.lastError().text(); }
I get the following debug information with
QT_DEBUG_PLUGINS=1
QFactoryLoader::QFactoryLoader() looking at "C:/Qt/5.15.2/mingw81_32/plugins/sqldrivers/qsqlpsql.dll" Found metadata in lib C:/Qt/5.15.2/mingw81_32/plugins/sqldrivers/qsqlpsql.dll, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QPSQL7", "QPSQL" ] }, "archreq": 0, "className": "QPSQLDriverPlugin", "debug": false, "version": 331520 } Got keys from plugin meta data ("QPSQL7", "QPSQL") QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/user/Documents/Qt_Projects/display-software/build/Desktop_Qt_5_15_2_MinGW_32_bit-Debug/debug/sqldrivers" ... Cannot load library C:\Qt\5.15.2\mingw81_32\plugins\sqldrivers\qsqlpsql.dll: Unknown error 0x000000c1. QLibraryPrivate::loadPlugin failed on "C:/Qt/5.15.2/mingw81_32/plugins/sqldrivers/qsqlpsql.dll" : "Cannot load library C:\\Qt\\5.15.2\\mingw81_32\\plugins\\sqldrivers\\qsqlpsql.dll: Unknown error 0x000000c1." QSqlDatabase: QPSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7 Available Drivers: ("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7") Failed to connect to database: "Driver not loaded Driver not loaded"
I checked the username password and the connection using pg admin 4 software with the hostname given above and it responds and works as expected.
The .dll file is in the path
C:\Qt\5.15.2\mingw81_32\plugins\sqldrivers\
as shown in the debug info above and I ran Dependencies on the dll file and I think everything is ok.
I uninstalled PostgreSQL 16 and installed PostgreSQL 9.6 32-bit version and added the bin folder to the System Path, although the actual database is on a linux 64-bit server on the network running PostgreSQL 13.
What could be the problem that I am not seeing and how do I load the QPSQL library?Thank you so much in advance.
-
See e.g. https://forum.qt.io/topic/136580/ - are you sure that you built for 32bit?
-
@Christian-Ehrlicher Thank you for responding.
Yes I am. I have only one kit configured for this projecct at the moment which is using MinGW 8.1 with QtCreator 14.0.1 (if it matters).