I have a simple code. The idea is just to connect to the MySQL database and print a message on the screen if the connection has been successful.
I have included in my "server.cpp" class this line:
#include <QtSql>
#include <QtSql>
To copy to clipboard, switch view to plain text mode
The code in the same class is:
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("user");
db.setPassword("password");
bool ok = db.open();
if(ok)
textBrowser->append("Success");
else
textBrowser->append("Not database");
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("user");
db.setPassword("password");
bool ok = db.open();
if(ok)
textBrowser->append("Success");
else
textBrowser->append("Not database");
To copy to clipboard, switch view to plain text mode
I am able to compile and also run this code. Their is no warning messages or anything like that, but it always prints "Not database" in the screen.
What do I need to do, to have MySQL and Qt in windows running ?
Bookmarks