PDA

View Full Version : QSqlDatabase: QMYSQL driver not loaded



prachik
13th January 2014, 11:27
I am using Qt Creator 2.4.1 in windows . While connecting to the database ,I am getting the following error

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC

Following is the code snippet :


QSqlDatabase db( QSqlDatabase::addDatabase( "QMYSQL") );
db.setHostName( "localhost" );
db.setDatabaseName( "testdb" );


db.setUserName( "root" );
db.setPassword( "password" );

if( !db.open() )
{
qDebug() << db.lastError();
qDebug() <<QSqlDatabase::drivers() ;
qFatal( "Failed to connect." );
}

qDebug( "Connected!" );
db.close();




Regards ,
Prachi

ChrisW67
13th January 2014, 20:40
The QMYSQL driver is not listed among the available drivers. You need to build it for your Qt and compiler. See the SQL Database Drivers docs