Can QSqlDatabase use MySQL?
-
QT supports MySql community version.
Add to your .pro file: QT += sql # that will allow the SQL library to be loaded.In your application do the following
#include <QSqlDatabase>
QSqlDatabase mdb; // instantiate a QSqlDatabase class variable
int someFunction()
{
mdb = QSqldatabase::addDatabase("QMYSQL", "MyConnection"); // load the MySql driver
mdb.setHostName(serverAddress);
mdb.setUserName(userName);
mdb.setPassword(passWord);
mdb.setDatabaseName(yourDefaultDatabaseName);
return mdb.open();
}
There is no attempt from me to check for errors. Kindly read the documentation.
Once the database is open, then you can use the high level classes of QT. You will see that the query classes use QSqlDatabase as parameter.Hope I helped.
-
Hi,
In addition to what @blaisesegbeaya wrote. Here you can find the complete list of SQL drivers supported by Qt.
Note that you need to have the MySQL client libraries installed. Depending on the version of them you have, you may have to rebuild the driver.