PDA

View Full Version : Using mysql database



raymadigan
23rd August 2016, 20:13
I am new to Qt and am trying to use the mysql database on a windows installation. I have already spent too much time and can't sort it out.

I have QTPLUGIN += qsqlmysql and QT += sql in the .pro file. When I load the project I get a message. two of them that it is redundant. It isn't any better when I leave the line out. I checked in the plugin directory and it is there.

I also have the -llibmysql entry added to the LIBS's path
win32:CONFIG(release, debug|release): LIBS += -L"C:/Program Files/MariaDB 10.1/lib/" -llibmysql

The application seems to build correctly.

my database access is copied from somewhere:


bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("testdb");
db.setUserName("root");
db.setPassword("rmsipw");
if (!db.open()) {
qDebug() << "Database error occurred";
return false;
}
return true;
}


when it runs I get:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3
Database error occurred
Not Connected:

Edit:
It is way more complicated then this: My application wants to compile with an old version of mingw on my machine. Even though the default kit is Desktop Qt 5.7.0 MSVC2013 64bit is the default Kit?

ChrisW67
23rd August 2016, 21:48
You should not need the LIBS entry, but you will need the Mysql client library (part of MariaDB/MySql) in the PATH or the same folder as the executable so Windows can find it when Qt tries to load the Qt plugin. The file is named something like libmysql.dll.

raymadigan
23rd August 2016, 22:24
Thanks for your help. I remove the lib entry. I really should have spent a little more time, I solved the problem and will make the thread solved. I used the QT_DEBUG_PLUGINS=1 and found out the real problem was it was using the wrong toolchain. Once I got past that issue it works great.