Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Can QSqlDatabase use MySQL?
jdent last edited by
I am very much impressed with the SQL classes and support in Qt. However, I usually work with MySQL Community Edition. Is there any support for that database? I don't see a driver for it...
blaisesegbeaya last edited by
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
QSqlDatabase mdb; // instantiate a QSqlDatabase class variable
mdb = QSqldatabase::addDatabase("QMYSQL", "MyConnection"); // load the MySql driver
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.
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.