PDA

View Full Version : MySQL Connection



Niunzin
16th January 2013, 20:36
Hey!

I need make an MySql connection, but I receive this error:
http://i.imgur.com/weMsU.png

My code:

#include <QtSql>

QSqlDatabase *db = new QSqlDatabase();
db->addDatabase( "QMYSQL3" ) ;
db->setDatabaseName( "dbToConnectTo" ) ;
db->setHostName( "localhost" ) ;
db->setUserName( "dbUser" ) ;
db->setPassword( "dbPassword" ) ;
if ( !db->open() ) {
QMessageBox *Ola = new QMessageBox(ui->centralWidget);
Ola->setText("Failed opening database dbToConnectTo\nReason:\n\n" + db->lastError().driverText() + "\n\n" + db->lastError().databaseText());
Ola->setIcon(QMessageBox::Warning);
Ola->setStyleSheet("background: none");
Ola->show();
}

In .pro:

QT += sql

Please help me :/
hugs :D

Lykurg
17th January 2013, 05:57
What does QSqlDatabase::drivers() say? You probably forget to distribute the right plugins alongside your application or haven't build the mysql plugin at all.

Lesiok
17th January 2013, 06:24
Or You don't have libraries from MySQL developer pack.

Niunzin
17th January 2013, 12:54
Have only QSQLITE in drivers... where I can download mysql drivers?

Lykurg
17th January 2013, 12:58
You have to compile them yourself. In the documentation you'll find how...

Niunzin
17th January 2013, 13:04
You have to compile them yourself. In the documentation you'll find how...Wow soo fast xD

Thanks! ;D