PDA

View Full Version : QSqlDatabase: QMYSQL driver not loaded



lise
1st June 2010, 12:04
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 ????

tbscope
1st June 2010, 12:21
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


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>
You only need #include <QtSql> because this will include all the others you mention


The connection code is:

QSqlDatabase::database( "connection-test" );
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.


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.

lise
1st June 2010, 13:06
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?

tbscope
1st June 2010, 13:09
Yes, read the following website carefully:
http://doc.qt.nokia.com/4.6/sql-driver.html