QsqlDatabase: QMYSQL driver not loaded but available
-
Hi all,
I know this is a common problem, I tried to follow other posts but I can't solve the problem.
This is my simply code taken by QT:#include <QSqlDatabase> #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("bigblue"); db.setDatabaseName("flightdb"); db.setUserName("acarlson"); bool ok = db.open(); qDebug() << "OK? " << ok; }
In the .pro
QT += core gui sql
The error is:
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
I'm using QT 5.9.1 MinGW 32bit.
I tired to download the zip file for 32 bit from here and the to import the .dll from "mysql-connector-c++-8.0.16-win32/lib" to "C:\Qt\5.9.1\mingw53_32\bin" and also "C:\Qt\5.9.1\mingw53_32\lib" but nothing changed, still the same error. Can somebody give me an hint?
-
Check e.g. with Dependency Walker if the mysql plugin (in plugins\sql) has all needed dependencies available.
-
could be that you will need the ms lib dll and you are with minGW??
-
@davidesalvetti Also, you can set QT_DEBUG_PLUGINS (https://doc.qt.io/qt-5/deployment-plugins.html) before starting your app and then expect its output.
-
@davidesalvetti I had a similar issue with MySQL plugin, as far as I known, Qt MySQL Plugin requires connector/c not connector/c++.
==> https://downloads.mysql.com/archives/c-c/
I had experience that it works with version 6.1.1 and older (version 6.1.2 and newer did not work on my PC)!Download it from mysql, and put a copy in C:\Qt\5.9.1\mingw53_32\bin, this should work.... in fact it works for me ;)
-
@KroMignon wow, it works now! I was taking the wrong connector, thank you for the right link!