Hi..
I have a trouble to connect to a mysql databse!!
I used a simple function to estblish connection in the main method :
bool createConnection(){
db.setDatabaseName("projet_cpp");
db.setPassword("passwrd");
db.setHostName("localhost");
if(!db.open()) {
QMessageBox::critical(0, qApp
->tr
("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
return false;
}
qApp->tr("Goood It Works.\n"
return true;
}
int main(int argc,char *argv[]){
if (!createConnection())
return 1;
..
..
}
bool createConnection(){
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setDatabaseName("projet_cpp");
db.setPassword("passwrd");
db.setHostName("localhost");
if(!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
QMessageBox::critical(0, qApp->tr(" open database"),
qApp->tr("Goood It Works.\n"
"Click ."), QMessageBox::Cancel);
return true;
}
int main(int argc,char *argv[]){
QApplication app(argc,argv);
if (!createConnection())
return 1;
..
..
}
To copy to clipboard, switch view to plain text mode
after execution I get always the messageBox telling that conexion was failled..
I read in Qt assistant that I should add the following include:
#include "C:\Qt\4.3.4\src\sql\drivers\mysql\qsql_mysql. cpp"
but it gives only errors !!
I tried :#include "C:\Qt\4.3.4\src\sql\drivers\mysql\qsql_mysql. h"
but it gives the error :mysql.h no such file or directory within qsql_mysql.h!!!
if someone could help !!
thanks
Bookmarks