Unsolved Qt MySQL link
-
Hi,
I'm having severe problems when attempting to access a MySQL database on Qt 5.10.0. It would seem that the driver/plugin is improperly linked and I can't figure out why/how to fix it.
The application error i receive is:QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7my .pro code is:
*QT += core gui sql
QT += networkgreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Test
QTPLUGIN += QSQLMYSQL
QTPLUGIN += QMYSQL
TEMPLATE = app
#C:\Qt\5.10.0\Src\qtbase\src\plugins\sqldrivers\mysql
INCLUDEPATH+=C:/Program Files (x86)/MySQL/INCLUDEPATH
LIBS+=C:/Program Files (x86)/MySQL/MySQL Server 5.7/lib/libmysql.libLIBS+=C:/Qt/5.10.0/Src/qtbase/src/plugins/sqldrivers/mysql/libmysql.lib
INCLUDEPATH+=include LIBS+=$$PWD/lib/mysqlcppconn.lib LIBS+=$$PWD/lib/libmysql.lib*
I'm almost certain there's no problem with this, but:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setPort(3306);
db.setDatabaseName("studentinfo");
db.setUserName("root");
db.setPassword("password");
if(!db.open())
QMessageBox::warning(this,"Error","Unable to connect to the database" + db.lastError().text());
else
QMessageBox::information(this,"Success","Connected to the database");I'm starting to get very frustrated with this and I've tried many methods suggested by youtube and previous forum posts regarding this matter (seems to be quite common). None of the solutions have worked thus far :/. I would highly appreciate some help, if someone would be kind enough to teamviewer me to help that would be incredible! - I'm new to Qt programming.
Thanks! -
[SOLVED]
For anyone with a similar issue:
- Download the C connector from the Qt website as a ZIP file
- Extract the file into a known folder
- Right click your project file >> click add library >> External library >> next
- Under Library file, click browse and locate the "libmysql.lib" file that you extracted
- Rebuild the project, run q make, make sure the MySQL server is running and connect to it
If this doesn't work, try the other Bit Version (if you used a 32-bit connector try the 64, vice versa)
-
Hi and welcome to devnet,
Glad you found a solution and thanks for sharing.
Where exactly did you download the C connector ?