Cannot connect to databases, Driver not loaded error.
-
I still think the sql plugin has some issues. Take a look what http://doc.qt.io/qt-5/qsqldatabase.html#drivers is telling you and make sure libqsqlmysql.so finds all it's dependencies (e.g. with ldd)
-
Hi and welcome to devnet,
To add to @Christian-Ehrlicher, this question has been asked many times already on this forum, please take the time to search through it.
-
Hi Christian, SGaist, thank you for your answers. As I mentioned in my post, I have already searched thoroughly the net for a solution, I have already re-compiled
libqsqlmysql.so
and callingldd
on it shows that not only does it not miss any dependency, it also links to the same libraries as the homonymous file from Debian's repositories. In particular, it links to the installed version oflibmariadbclient
[Debian switched to MariaDB which is a fork of MySQL and a drop-in replacement].In any case, I also mentioned in my previous post that the problem is not specific to the MySQL driver, but I get the same error even if I try to use SQLite as a backend.
What is the next thing that I can try?
-
Then start your application with the
QT_DEBUG_PLUGINS
environment variable set to 1. That will give you some more information about what is happening. -
Thanks for the suggestion!
This is the relevant outputQFactoryLoader::QFactoryLoader() checking directory path "/opt/Qt/5.10.1/gcc_64/plugins/sqldrivers" ... QFactoryLoader::QFactoryLoader() looking at "/opt/Qt/5.10.1/gcc_64/plugins/sqldrivers/libqsqlite.so" Found metadata in lib /opt/Qt/5.10.1/gcc_64/plugins/sqldrivers/libqsqlite.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QSQLITE" ] }, "className": "QSQLiteDriverPlugin", "debug": false, "version": 330241 } Got keys from plugin meta data ("QSQLITE") QFactoryLoader::QFactoryLoader() looking at "/opt/Qt/5.10.1/gcc_64/plugins/sqldrivers/libqsqlmysql.so" Found metadata in lib /opt/Qt/5.10.1/gcc_64/plugins/sqldrivers/libqsqlmysql.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QMYSQL3", "QMYSQL" ] }, "className": "QMYSQLDriverPlugin", "debug": false, "version": 330241 } Got keys from plugin meta data ("QMYSQL3", "QMYSQL") loaded library "/opt/Qt/5.10.1/gcc_64/plugins/sqldrivers/libqsqlmysql.so" "Driver not loaded Driver not loaded"
Meanwhile I have run the Qt example
sqlbrowser
and it does successfully connect to my MySQL local server, it shows me the database and the tables. This makes me suspect that there is an error in the code, but what could it be? -
Debug VS Release version of the plugin ?
-
Did you build your plugin for both debug and release ?
-
@SGaist I built just one, with the default configuration. I will check which one when I get back to my home pc. What difference does it make? Could it work with one but not the other one?
@Homer2000 I am using a shared library, except my distribution [like many others] now uses MariaDB as a replacement for MySQL, so I link to
libmariadb.so
or something similar -
@Homer2000 No, by default the Qt MySQL plugin links against the MySQL client libraries.
You can build it to use MariaDB though.
-
Ok, I found out what I was doing wrong.
The code that I was using isQSqlDatabase db; db.addDatabase("QMYSQL");
and it was giving me the error above, whereas the correct way to do it is
QSqlDatabase db; db = QSqlDatabase::addDatabase("QMYSQL");
and with this code it works fine.
I don't know why this is the case, I guess today I just learnt something new on Qt, thanks for the help everyboody!
-
@mleoni said in Cannot connect to databases, Driver not loaded error.:
I don't know why this is the case,
Because QSqlDatabase::addDatabase() is a static function - no Qt magic here.
-
Please take the time to read the QSqlDatabase documentation. It shows how to use it properly.