I am having trouble connecting from Qt (Windows) to my database.
I am using MySQL and the server is running. With some GUI clients I am connecting to the database, but when I try to connect from Qt, I just cannot.
I have included "#include <QtSql>" in my .cpp
db.setHostName("localhost");
db.setDatabaseName("testdata");
db.setUserName("test");
db.setPassword("password");
bool ok = db.open();
if(ok)
textBrowser->append("Conection to DATABASE");
else
textBrowser->append("error to DATABASE");
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("testdata");
db.setUserName("test");
db.setPassword("password");
bool ok = db.open();
if(ok)
textBrowser->append("Conection to DATABASE");
else
textBrowser->append("error to DATABASE");
To copy to clipboard, switch view to plain text mode
I have also included "QT += sql" to my .pro
I can compile and run the code perfectly, there is no errors in it. But, but I guess that there is no connection, because I always end up printing the "error to Database" message on the screen.
Help please ?
Bookmarks