QSqlDatabase: QMYSQL driver not loaded
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 ????
Re: QSqlDatabase: QMYSQL driver not loaded
Quote:
Originally Posted by
lise
After several days of trying to make a connection to my MYSQL database work I am almost giving up, so could someone please HELP!
Let's try to get this working
Quote:
I am using Qt4.2 and MySql server version 5.0.83 in Ubuntu Karmic Koala. My header file has these includes:
Code:
#include <QSqlDatabase>
#include <qsqldatabase.h>
#include <QSqlError>
#include <QSqlQuery>
#include <QtSql>
#include <QMYSQLDriver>
#include <QtSql/QMYSQLDriver>
You only need #include <QtSql> because this will include all the others you mention
You can delete this line, it doesn't do what you want or think it does. It returns the database with the name "connection-test", it does not set the connection name.
Quote:
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
It tells you exactly what is wrong. The Qt MySql driver is not found.
You will need to build the driver and install it in the correct plug-in folder of your Qt installation.
Or, try your package manager to see if you can just download it.
Re: QSqlDatabase: QMYSQL driver not loaded
You will need to build the driver and install it in the correct plug-in folder of your Qt installation.
[/QUOTE]
My problem is I am very new to Qt. I think I have the driver for MySql, QMYSQLDRIVER, but my suspicion is that it is not placed where the program searches for it. Is there a standard or a rule that says which is the correct plug-in forlder?
Re: QSqlDatabase: QMYSQL driver not loaded
Yes, read the following website carefully:
http://doc.qt.nokia.com/4.6/sql-driver.html