PDA

View Full Version : QSqlDatabase: QMYSQL driver not loaded



onder
14th August 2006, 12:27
hi,

i am trying to connect mysql server bu i take this error :
"QSqlDatabase: QMYSQL driver not loaded"

i search forum and google i didnt find works answer.

i am using linux and my qt version 4.2
i install mysqlserver, mysqlclient and mysql libs.

please help.

thanks alot

onder

jacek
14th August 2006, 12:29
How did you install Qt?

onder
14th August 2006, 12:34
i am using pardus(linux distrubition).
i use pardus packet manager and i install
qt4
qt-sql-mysql
qt-doc

but default qt files still there (qt3)

onder

jacek
14th August 2006, 12:40
i use pardus packet manager and i install
qt4
qt-sql-mysql
Are you sure that this qt-sql-mysql package if for Qt 4.2?

onder
14th August 2006, 12:48
yes i checked :qt-sql-mysql for qt 4x

jacek
14th August 2006, 17:37
Try this:
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QStringList>
#include <QtDebug>

int main( int argc, char **argv )
{
QCoreApplication app( argc, argv );
qDebug() << QSqlDatabase::drivers();
}it should print all available drivers (don't forget about QT += sql).

Make sure you create QCoreApplication or QApplication instance before you try to connect to the database.

onder
14th August 2006, 21:04
hi ,
i compile and run yopur code.
its result

("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QPSQL7", "QPSQL")

jacek
14th August 2006, 21:09
And how about this?
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QStringList>
#include <QtDebug>

int main( int argc, char **argv )
{
QCoreApplication app( argc, argv );
qDebug() << QSqlDatabase::drivers();
QSqlDatabase db( QSqlDatabase::addDatabase( "QMYSQL" ) );
qDebug() << db.lastError();
}

onder
14th August 2006, 21:18
("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QPSQL7", "QPSQL")
QSqlError(-1, "", "")

jacek
14th August 2006, 21:56
QSqlError(-1, "", "")
So it seems to work and most probably the problem lies in your code. As I already wrote, make sure you create QApplication or QCoreApplication instance before you use classes from the QtSql module.

onder
15th August 2006, 17:18
hi,

i understood but late understood.
you are right : problem QApplication instance problem.
thanks a lot

Onder

noka
29th March 2017, 15:26
("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7")
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
QSqlError("", "Driver not loaded", "Driver not loaded")
Press <RETURN> to close this window...



Hello, this is my console output whenever I run this code below:

#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QStringList>
#include <QtDebug>

int main( int argc, char **argv )
{
QCoreApplication app( argc, argv );
qDebug() << QSqlDatabase::drivers();
QSqlDatabase db( QSqlDatabase::addDatabase( "QMYSQL" ) );
qDebug() << db.lastError();
}


What could be the problem, please?
Thanks in advance.
I'm using Qt5.8

Lesiok
29th March 2017, 15:43
You have to install Mysql client. QMysql driver is only interface to standard Mysql client.