I’ve got the following problem with QODBC driver:
bool Dialog::createOdbcConnection(QSqlDatabase * db, QString odbcName,QString user,QString pass)
{
db = new QSqlDatabase();
db->addDatabase("QODBC");
db->setDatabaseName(odbcName);
if(!user.isEmpty())
db->setUserName(user);
if(!pass.isEmpty())
db->setPassword(pass);
qDebug() << QSqlDatabase :: drivers();
if (!db->open())
{
QMessageBox mgs;
qDebug() << db->lastError().text();
mgs.setText(db->lastError().text());
mgs.exec();
return false;
}
return true;
}
qDebug() << QSqlDatabase :: drivers(); returns ("QSQLITE", "QODBC3", "QODBC"), but the program doesn’t open my database, db->open() returns false and the error is "Driver not loaded Driver not loaded"
Whats the use of the QSqlDatabase Parameter in your createOdbcConnection-Method?
I would rather remove it from there, define a QSqlDatabase Object in your Class-Definition:
And initialize it in your Class-Constructor:
That should work!