How do I connect to the MySQL database using QT4 and Qt Creator? I have no idea how I should proceed, if anyone can help me please..
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
this question is very shallow, but i will try to provide some ressources as this shows up pretty on top on many searches.
First of all, you will have to compile the MYSQL driver for the QtCreator for your operating system.
For Windows, check
QT MySql connectivity using Windows XP, Qt Creator 4.5.2(windows 32 bit)
Instructions for MacOS (and probably Linux) can be found here
http://www.qtcentre.org/threads/45296-QSqlDatabase-QMYSQL-driver-not-loaded
Once your qt install includes the mysql driver, you can use the database with the (QSqlDatabase)(developer.qt.nokia.com/doc/qsqldatabase.html) class. Copying from here:
After that, you can use QSqlQuery to work with the database handle, e.g.
and print the results like
Code is not tested, but the Qt Documentation should clarify all details