Solved QMYSQL Driver not loaded
-
I've installed Qt5.6.0 just now and I'm getting the error when trying to connect to the database. my code is very simple just trying to test to see if I can connect to the database I've set up. It's a MariaDB database. How can I fix this?
This is What I get:
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7 "Driver not loaded Driver not loaded"
my code is:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("192.168.43.252"); db.setDatabaseName("readers"); db.setUserName("moki"); db.setPassword("mapra"); if(!db.open()) qDebug() << db.lastError().text();
-
You have already compiled the driver?
Download from here: https://dev.mysql.com/downloads/connector/cpp/ and follow the instruccions:
http://doc.qt.io/qt-4.8/sql-driver.htmlYou need a sqldriver folder with the plugin under your run directory
-
@hrompato I've installed it using the installer. Do I have to compile it by myself?
-
Yes, see my comments over
-
@hrompato will it work if I install
libmysqlcppconn-dev
using my package manager? -
@hrompato I'm sorry but I can't figure out how to do the things you just mentioned could you explain how to do them in more details? There's no directory name
src/plugins/sqldrivers/mysql
anywhere within my Qt installation path. -
@morkia in Linux, if you install libmysqlcppconn, doesn't need compile the plugin.
Try it -
@hrompato I did but the problem is still there.
-
This post is deleted! -
@morkia It works for me
I'm using /usr/lib/libmysqlcppconn.so.7 and Qt5.5.1 in Debian.What is the distribution that you use?
You have declared Qt + = sql in the pro file? -
Here's what I did. I just compiled the plugin in
Src/qtbase/src/plugins/sqldrivers/mysql
usingqmake mysql.pro
and thenmake
andmake install
and that did the trick. I also Installedlibmysqlcppconn7
andlibmysqlcppconn-dev
byapt-get
.