After several days of trying to make a connection to my MYSQL database work I am almost giving up, so could someone please HELP!
I am using Qt4.2 and MySql server version 5.0.83 in Ubuntu Karmic Koala. My header file has these includes:
#include <QSqlDatabase>
#include <qsqldatabase.h>
#include <QSqlError>
#include <QSqlQuery>
#include <QtSql>
#include <QMYSQLDriver>
#include <QtSql/QMYSQLDriver>
The connection code is:
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("xxx");
db.setUserName("xxx");
db.setPassword("xxxx");
QSqlDatabase::database( "connection-test" );
db.open();
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
QSqlQuery query;
query.exec("select xxx from yyy");
return true;
}
And what I get is a message called Database Error saying: Driver not loaded Driver not loaded
The Application Output is:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QSQLITE2 QPSQL7 QPSQL
Could someone please tell me what needs to be done ????
Bookmarks