QPSQL driver not loaded
-
Hello!!
I have an example application that uses a Postgre database.
I make the connection like this:
m_pDatabase = new QSqlDatabase(QSqlDatabase::addDatabase("QPSQL")); if (m_pDatabase != nullptr) { m_pDatabase->setConnectOptions(); m_pDatabase->setHostName(sServerName); m_pDatabase->setDatabaseName(sDatabaseName); m_pDatabase->setUserName(sUserName); m_pDatabase->setPassword(sPassword); } if (m_pDatabase->open()) { return true; } else { qDebug() << "Error al abrir: " << m_pDatabase->lastError().text(); return false; }
Ok, in my example application it works successfully but, when I copy this code to another application for using the same database it doesn't work:
QSqlDatabase: QPSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
What could be happening?
Thank you very much!
-
@SGaist I have the same problem. I have removed the execution folder and comment the QMAKE_POST_LINK line, but it doesn't work. I'm a little desperate, but I am very grateful for your time.
@ivanicy Well, I have solved the problem. I have copied this dlls from PostgreSQL to the .exe folder:
libiconv-2.dll
libintl-8.dll
libpq.dlland... it works!!
Maybe the problem was that I created this app before I installed the PostgreSQL and the app doesn't integrate the postgre dlls or something like that.
In any case, copying this dlls solves the problem. Thank you very much guys for your help!!
-
Hello!!
I have an example application that uses a Postgre database.
I make the connection like this:
m_pDatabase = new QSqlDatabase(QSqlDatabase::addDatabase("QPSQL")); if (m_pDatabase != nullptr) { m_pDatabase->setConnectOptions(); m_pDatabase->setHostName(sServerName); m_pDatabase->setDatabaseName(sDatabaseName); m_pDatabase->setUserName(sUserName); m_pDatabase->setPassword(sPassword); } if (m_pDatabase->open()) { return true; } else { qDebug() << "Error al abrir: " << m_pDatabase->lastError().text(); return false; }
Ok, in my example application it works successfully but, when I copy this code to another application for using the same database it doesn't work:
QSqlDatabase: QPSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
What could be happening?
Thank you very much!
@ivanicy said in QPSQL driver not loaded:
What could be happening?
Set QT_DEBUG_PLUGINS environment variable to one 1 before starting your application, start your app and check the output (or post it here).
-
@ivanicy said in QPSQL driver not loaded:
What could be happening?
Set QT_DEBUG_PLUGINS environment variable to one 1 before starting your application, start your app and check the output (or post it here).
@jsulm Ok, this is the output of my example app that works fine:
Got keys from plugin meta data ("QPSQL7", "QPSQL") QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/Ivan/Desktop/Pruebas/DataBase/build-DataBase-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug/debug/sqldrivers" ... loaded library "C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/plugins/sqldrivers/qsqlpsqld.dll"
And this is the output for my other app that doesn't work:
Cannot load library C:\Users\Ivan\Desktop\Proyectos\sw_RedLook_Fix\build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\debug\sqldrivers\qsqlpsqld.dll: No se puede encontrar el módulo especificado. QLibraryPrivate::loadPlugin failed on "C:/Users/Ivan/Desktop/Proyectos/sw_RedLook_Fix/build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug/debug/sqldrivers/qsqlpsqld.dll" : "Cannot load library C:\\Users\\Ivan\\Desktop\\Proyectos\\sw_RedLook_Fix\\build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\\debug\\sqldrivers\\qsqlpsqld.dll: No se puede encontrar el módulo especificado." QSqlDatabase: QPSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
Apparently in the first case it is taking the dll from msvc2017 and in the second from the program folder it is not? How can I change it?
Thank you very much!
-
You can delete the 'sqldrivers' folder (and any other Qt plugin folders) from your build directory; it should then load from the Qt directory.
-
@mchinand In .pro file I only add "QT += sql". But I don't why it can't find the qsqlpsqld.dll file. This dll is in the sqldrivers folder. How can I make the QFactoryLoader look in the correct folder?
-
@mchinand I have another clue. I have tried to execute the application from the application folder (out of Qt) and it works...
-
Hi,
Did you build the plugin both for debug and release ?
Note that the length of your application output with regard to the QPSQL driver messages indicates that you likely did not properly set the QT_DEBUG_PLUGINS environment in Qt Creator. It should be done in the Run part of the Project panel.
You should be swamped with plugin related messages and have something more informative with regard to what happens when the plugin loading fails.
-
Hi,
Did you build the plugin both for debug and release ?
Note that the length of your application output with regard to the QPSQL driver messages indicates that you likely did not properly set the QT_DEBUG_PLUGINS environment in Qt Creator. It should be done in the Run part of the Project panel.
You should be swamped with plugin related messages and have something more informative with regard to what happens when the plugin loading fails.
@SGaist I have this:
Got keys from plugin meta data ("QPSQL7", "QPSQL") Cannot load library C:\Users\Ivan\Desktop\Proyectos\sw_RedLook_Fix\build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\debug\sqldrivers\qsqlpsqld.dll: No se puede encontrar el módulo especificado. QLibraryPrivate::loadPlugin failed on "C:/Users/Ivan/Desktop/Proyectos/sw_RedLook_Fix/build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug/debug/sqldrivers/qsqlpsqld.dll" : "Cannot load library C:\\Users\\Ivan\\Desktop\\Proyectos\\sw_RedLook_Fix\\build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\\debug\\sqldrivers\\qsqlpsqld.dll: No se puede encontrar el módulo especificado." QSqlDatabase: QPSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7 Error al abrir: "Driver not loaded Driver not loaded" ERROR: "Driver not loaded Driver not loaded"
I have two doubts here:
- ¿Why it couldn't find qsqlpsqld.dll file if the path is correct. I have this dll in sqldrivers folder.
- Why Qt creates this folder there if in my example application it doesn't create anything (and it works correctly)
-
One thing I did not realise directly is that it tries to load them from your application folder.
How did the plugins go there ?
Did you run windeployqt at some point in that folder ?Did you build the plugins yourself ?
Do you have the PostreSQL .dll contains folder in your PATH environment variable ?
One important thing: all the manipulations of the environment variables should be done within Qt Creator and not at your machine level.
-
One thing I did not realise directly is that it tries to load them from your application folder.
How did the plugins go there ?
Did you run windeployqt at some point in that folder ?Did you build the plugins yourself ?
Do you have the PostreSQL .dll contains folder in your PATH environment variable ?
One important thing: all the manipulations of the environment variables should be done within Qt Creator and not at your machine level.
@SGaist I have this in .pro. But I have it before add QT += sql:
isEmpty(TARGET_EXT) { TARGET_CUSTOM_EXT = .exe } else { TARGET_CUSTOM_EXT = $${TARGET_EXT} } DEPLOY_COMMAND = windeployqt CONFIG( debug, debug|release ) { # debug DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT})) } else { # release DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT})) } #Uncomment the following line to help debug the deploy command when running qmake #warning($${DEPLOY_COMMAND} $${DEPLOY_TARGET}) QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_TARGET}
I do the same thing in both applications, I only add QT += sql
-
@SGaist I have this in .pro. But I have it before add QT += sql:
isEmpty(TARGET_EXT) { TARGET_CUSTOM_EXT = .exe } else { TARGET_CUSTOM_EXT = $${TARGET_EXT} } DEPLOY_COMMAND = windeployqt CONFIG( debug, debug|release ) { # debug DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT})) } else { # release DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT})) } #Uncomment the following line to help debug the deploy command when running qmake #warning($${DEPLOY_COMMAND} $${DEPLOY_TARGET}) QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_TARGET}
I do the same thing in both applications, I only add QT += sql
-
Nuke your build folder and remove the windeployqt call. Do you still have the problem ?