[SOLVED]Database connexion in a GUI apps with Qt5 (Mingw) seems impossible ?
-
Hello,
My driver's compilation looks fine (MySQL) and the dispatching is:
Qt/Qt5.0.1/5.0.1/mingw47_32/bin >libmysql.dll
Qt/Qt5.0.1/5.0.1/mingw47_32/lib >libqsqlmysql.a et libqsqlmysqld.a
Qt/Qt5.0.1/5.0.1/mingw47_32/lib/plugins/sqldrivers >qsqlmysql.dll et qsqlmysqld.dllThat's works fine in a Console app only !...
but when i try with a GUI apps and following code:
@#include "dialog.h"
#include <QApplication>bool createConnection()
{
QString myDriver = "QMYSQL"; //"QODBC"QSqlDatabase db = QSqlDatabase::addDatabase(myDriver); db.setHostName("localhost"); db.setUserName("root"); db.setPassword(""); db.setDatabaseName("test"); //"ODBC_DBTest" if(!db.open()) { qDebug() << "Connexion FAILED."; qDebug() << "Driver disponible: " << db.drivers(); qDebug() << "Driver fonctionnel" << myDriver << ":" << db.isDriverAvailable(myDriver); qDebug() << "numero de l'erreur: " << db.lastError().number(); qDebug() << "database erreur: " << db.lastError().databaseText(); qDebug() << "driver erreur: " << db.lastError().driverText(); return false; }else{ qDebug() << "Your are now connect to " << db.hostName(); return true; }
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
if(!createConnection())
return 1;Dialog w; w.show(); return a.exec();
}
@Connexion FAILED.
Driver disponible: ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3")
Driver fonctionnel "QMYSQL" : true
numero de l'erreur: 2005
database erreur: "Unknown MySQL server host 'localhost' (0)"
driver erreur: "QMYSQL: Unable to connect"What did i miss or how can i find a hack for it ?
-
the error message just says that i couldn't find a mysql server on "localhost"
Are you sure that you have a mysql server running on your computer?! -
alternatively you can try to use "127.0.0.1" .
And make sure that C:\Windows\System32\drivers\etc\hosts has the following entry in it:
@127.0.0.1 localhost@