Solved QSqlDatabase:QPSQL Driver not loaded Driver not loaded
-
This question has been asked many times as I have seen many posts on this. But nothing seems to be working for me. I am running a Qt version 5.5.1 with QMake version 3.0 in Ubuntu 16.04. It is causing a runtime error as
QSqlDatabase: unknown driver not loaded
QSqlDatabase: available drivers: QSQLITE QPSQL QPSQL7
"\uFFFF:Driver not loaded Driver not loaded"
As the above available drivers I have my .so files at the "sqldriver" folder in Qt plugins folder. ldd on my executable and also on the library files are fine and dependencies are found. I am using a Postgresql 9.5 and I have tried to pass in the \bin and \lib paths of the Postgresql to Qt through Run Environment variables. Setting my QT_DEBUG_PLUGINS=1 gave
Debug: 14.05.2018 09:51:55.831 QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers" ...
Debug: 14.05.2018 09:51:55.831 QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so"
Warning: 14.05.2018 09:51:55.831 Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so, metadata=
{
"IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
"MetaData": {
"Keys": [
"QSQLITE"
]
},
"className": "QSQLiteDriverPlugin",
"debug": false,
"version": 328961
}Debug: 14.05.2018 09:51:55.831 Got keys from plugin meta data ("QSQLITE")
Debug: 14.05.2018 09:51:55.831 QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlpsql.so"
Warning: 14.05.2018 09:51:55.831 Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlpsql.so, metadata=
{
"IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
"MetaData": {
"Keys": [
"QPSQL7",
"QPSQL"
]
},
"className": "QPSQLDriverPlugin",
"debug": false,
"version": 328961
}which looks fine. Anyone with an idea of what maybe wrong? Thanks
-
I suspect that some dependency library of libqsqlpsql.so missing. OR it could be issue of version mismatch between what qt is expecting and what is available in the system.
-
A ldd on the libqsqlpsql.so library shows all dependencies are found. The QT_DEBUG_PLUGINS shows the version as
"className": "QPSQLDriverPlugin",
"debug": false,
"version": 328961This same version with Qmake version 3.0 and Qt version 5.5.1 is running in another computer. A link is established with the Database but not for me. What can I check with his computer and mine?
-
Also QT_DEBUG_PLUGINS = 1 gave an output that the driver .so files are being looked at the directory my binary file is generated. So I even created a directory named "sqldriver" in the directory "\bin" and moved by library files but didnt work.
-
@ram070787 Is it all you get if you set QT_DEBUG_PLUGINS=1 ?
-
@jsulm Yes !
Debug: 14.05.2018 13:24:49.864 Application startUp
Loc: [../../controlsystem/mycontrol/mycontrol.cpp:1452]
Debug: 14.05.2018 13:24:49.864 QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers" ...
Debug: 14.05.2018 13:24:49.864 QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so"
Warning: 14.05.2018 13:24:49.864 Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so, metadata=
{
"IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
"MetaData": {
"Keys": [
"QSQLITE"
]
},
"className": "QSQLiteDriverPlugin",
"debug": false,
"version": 328961
}Debug: 14.05.2018 13:24:49.864 Got keys from plugin meta data ("QSQLITE")
Debug: 14.05.2018 13:24:49.864 QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlpsql.so"
Warning: 14.05.2018 13:24:49.864 Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlpsql.so, metadata=
{
"IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
"MetaData": {
"Keys": [
"QPSQL7",
"QPSQL"
]
},
"className": "QPSQLDriverPlugin",
"debug": false,
"version": 328961
}Debug: 14.05.2018 13:24:49.864 Got keys from plugin meta data ("QPSQL7", "QPSQL")
Debug: 14.05.2018 13:24:49.864 QFactoryLoader::QFactoryLoader() checking directory path "/home/workspacetest/branches/user/build-controlsystem-Desktop-Debug/mycontrol/sqldrivers" ...
Warning: 14.05.2018 13:24:49.864 QSqlDatabase: unknown driver not loaded
Warning: 14.05.2018 13:24:49.864 QSqlDatabase: available drivers: QSQLITE QPSQL QPSQL7
Critical: 14.05.2018 13:24:49.864 PtsSystem: Not able to access database. "\uFFFF:Driver not loaded Driver not loaded"
Loc: [../../controlsystem/mycontrol/mycontrol.cpp:1452]
Fatal: 14.05.2018 13:24:49.864 Caught exception: :Driver not loaded Driver not loaded.This is the complete output
-
@ram070787 My guess is that PostgreSQL client library is missing. ldd will not help here as Qt uses dlopen() to load it, it does not link against it.
-
@jsulm Will "sudo apt-get install postgresql-client" install client libraries to my computer for Postgresql? If yes I have already installed these files in my computer.
-
@ram070787 I don't know how Debian/Ubuntu packages this stuff. You can search for them on your system, not sure which one is used by Qt (the C or C++ one, see https://wiki.postgresql.org/wiki/Client_Libraries).
-
-
Hi and welcome to devnet,
Did you install PostgreSQL development packages for your distribution ?
-
@SGaist Yes I have installed "postgresql-dev" on my computer. Also this error below..
QSqlDatabase: unknown driver not loadedQSqlDatabase: available drivers: QSQLITE QPSQL QPSQL7
"\uFFFF:Driver not loaded Driver not loaded"
I was able to recreate this error in another machine when I removed libqsqlpsql.so from the sqldriver folder in the Qt installtion and the error looked like
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QPSQL QPSQL7
"\uFFFF:Driver not loaded Driver not loaded"
I can understand this error. But mine shows "unknown".
-
I am working on codes written by other persons and have no idea how they did this . It seems to me that QSqldatabase is looking for "unknown driver" and is not able to load it. Is there any reason that this can happen?
-
@SGaist These are my postgres packages installed
- postgresql/xenial-updates,xenial-updates,xenial-security,xenial- security,now 9.5+173ubuntu0.1 all [installed]
- postgresql-9.5/xenial-updates,xenial-security,now 9.5.12-0ubuntu0.16.04 amd64 [installed,automatic]
- postgresql-client-9.5/xenial-updates,xenial-security,now 9.5.12-0ubuntu0.16.04 amd64 [installed]
- postgresql-client-common/xenial-updates,xenial-updates,xenial-security,xenial-security,now 173ubuntu0.1 all [installed]
- postgresql-common/xenial-updates,xenial-updates,xenial-security,xenial-security,now 173ubuntu0.1 all [installed,automatic]
- postgresql-contrib-9.5/xenial-updates,xenial-security,now 9.5.12-0ubuntu0.16.04 amd64 [installed,automatic]
I also have installed libpq5 and libpq-dev on my computer.
-
@ram070787 What about libpqxx-dev ?
-
There's something mighty fishy here.
Did you install of Qt's development packages from your distribution ?
What do you get if you runldd
on the PostgreSQL plugin ? -
@SGaist If I am right by Qt development package you mean the qtdeclarative5-dev packages. I had those installed.
I did not understand where this PostgreSQL plugin is? A "ldd psql" had all the dependencies.
-
@jsulm Yeah those were installed.
-
I already spent a week trying to find the error and unsuccessful. so I have reinstalled my complete system. I will try to install all essential libraries and softwares and will come back here again. Thanks everyone for your help.
-
Hi guys. I have found the reason for this. But not sure what to do about this. Maybe you guys are experienced in this.
My application runs by reading an .ini file in the folder "etc/myfile.ini" and automatically generates the same myfile.ini in my home folder with some details about my login credentials to the application that is built by Qt. The first run in my Qt opens my application and an .ini file is generated in my home folder. When I stop my application and restart it is gives "unknown driver error". So this .ini file is not generated again afresh. I have to delete the old .ini file in my home folder before running my application again.
Also my application gets a connection with the Sql database and the details about the database are written in the .ini file generated in my home folder. These details are written in another computer and not in mine.