Hello, at the moment I'm noob in handling servers with databases. I am using Qt Creator 5.3 to develop my project, and I decided to incorporate a Mysql 5.7 bank to it. I'm trying to establish a simple connection between my application and the MySql database, however I always encounter the following error message:
InsomecasesIlookedforsimilarproblems,andinmostcaseswereabletosolvetheproblembycopyingthelibmysql.dllfilefromtheC:\ProgramFiles\MySQL\MySQLServer5.7\libfoldertotheprojectexecutablefolderC:\Users\Syn\Desktop\build-Bank_MySql-Desktop_Qt_5_3_MinGW_32bit-Debug\debug.Butevenfollowingthisstep,andaddingthelibpathofthedlltotheenvironmentvariables,theproblempersists.SinceIdidnotmessaroundwiththisdatabaseandthistypeofconnectionbefore,Ihavenoideawhatitmightbe.HereisthetestcodeI'musing:
#include<QCoreApplication>#include<QtSql>#include<QSqlDatabase>#include<QSqlQuery>#include<QDebug>intmain(intargc,char*argv[]){QCoreApplicationa(argc,argv);QSqlDatabasedb;db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setPort(3306);
db.setDatabaseName("log_user");
db.setUserName("root");
if(db.open()){
qDebug() << "Conexão foi aberta com sucesso!";
}
else{
qDebug() << db.lastError().text();
qApp->quit();
}
QSqlQuery qery("select * from log_user");
if(qery.exec()){
while(qery.next())
qDebug() << qery.value(0).toString() << "|" << qery.value(1).toString();
}
else{
qDebug() << "Erro Fatal: " << qery.lastError().text();
}
return a.exec();
}
In the code I'm trying to access the database table and display its contents in the console, but I always come across the same error message. Would anyone else know of another step I might have missed or some solution? Thanks in advance.