Hello,
I've modified one of the Sql connector examples included with the Qt installation to connect to a mysql database. I'm using the eval version with MSVS 2005. The code compiles but when I try to call createConnection() I get a "Driver Not Loaded" error. The main thing I don't understand is that this worked under 4.3.3 but breaks now, even though 4.3.4 is completely backwards compatible. Here's the code. Thanks in advance.
#ifndef MYSQL_CONNECTION_H
#define MYSQL_CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QString>
#include <QStringList>
static bool createConnection()
{
db.setDatabaseName("scheduling");
db.setHostName("127.0.0.1");
db.setUserName("root");
db.setPassword("dora");
if (!db.open()) {
"Unable to establish a database connection. " + db.lastError().text() + ".\n\n\n"
return false;
}
return true;
}
#endif
#ifndef MYSQL_CONNECTION_H
#define MYSQL_CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QString>
#include <QStringList>
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setDatabaseName("scheduling");
db.setHostName("127.0.0.1");
db.setUserName("root");
db.setPassword("dora");
if (!db.open()) {
QMessageBox::critical(0, "Cannot open database",
"Unable to establish a database connection. " + db.lastError().text() + ".\n\n\n"
"Click Cancel to exit.", QMessageBox::Cancel);
return false;
}
return true;
}
#endif
To copy to clipboard, switch view to plain text mode
Bookmarks