Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt5.8.0 mysql driver not found!
orcav last edited by
I have installed Qt5.8.0 on Ubuntu 16.04 and I wish to use mysql. mysql is installed in it default location (/usr/bin ) and runs fine from the command line.
Running the Example program sqlbrowser, I find the error "Driver not loaded"
This error is generated by the call: QSqlDatabase::addDatabase
I have here (below) the simplest example of this difficulty. Here is the output from two calls:
drivers = QSqlDatabase::drivers(); returns ("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7") which makes me think that QMYSQL means there is a connection to mysql.
But, QSqlDatabase::addDatabase returns the driver not found error.
I confirmed that after I installed sqlite, the addDatabase returns a good connection to sqlite.
So, my question is what needs to be done to link Qt5.0 with it's libqsqlmysql.so library to my actual implementation of mysql?
Below is a tiny bit of code and resulting output:
int main(int argc, char *argv)
QCoreApplication a(argc, argv);
qDebug() << "test mysql"; QStringList drivers = QSqlDatabase::drivers(); qDebug()<<"list drivers"; qDebug()<<drivers; QString driverName = "QSQLITE"; qDebug()<<"TRY -- addDatabase"<<driverName; QSqlError err; QSqlDatabase db = QSqlDatabase::addDatabase(driverName, "Browser0"); err = db.lastError(); qDebug()<<"lastError for"<<driverName<<"is"<<err; driverName = "QMYSQL"; qDebug()<<" ";qDebug()<<"TRY -- addDatabase"<<driverName; db = QSqlDatabase::addDatabase(driverName, "Browser1"); err = db.lastError(); qDebug()<<"lastError for"<<driverName<<"is"<<err; return a.exec();
("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7")
TRY -- addDatabase "QSQLITE"
lastError for "QSQLITE" is QSqlError("", "", "")
TRY -- addDatabase "QMYSQL"
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
lastError for "QMYSQL" is QSqlError("", "Driver not loaded", "Driver not loaded")
ldd libqsqlmysql.soto see against which version of MySQL it was built against. If different than yours then you'll have to re-build the plugin. Note that you do not have to re-build all of Qt, just the plugin.
orcav last edited by
Ldd reports the need for three libraries:
libmysqlclient.so.18 => not found libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff7894e4000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff7892ca000) libssl.so.10 => not found libcrypto.so.10 => not found
Hmmm. I struggled with this problem two years ago and here it is again. Mr. Gaist has suggested I need to do is rebuild the plugin. I have spent several days trying to do this without success. (Trying to follow http://doc.qt.io/qt-5/sql-driver.html ) If there is any clear path showing how to get qt to link to mysql, I would so love to find and follow it.
What is not working for you ?
Because basically you have to:
- Download Qt's source (you can do that through the installer or the maintenance tool)
- Unpack it if you downloaded the tar file
- Install the dev packages for the missing libraries from your distribution
- Follow the documentation
Don't forget to use the full path to your installed Qt qmake otherwise you are going to use your distribution's Qt which is not what you want in this case.