PDA

View Full Version : qt connect with mysql in fedora



sachinmcajnu
10th March 2011, 18:16
hi am trying to connect mysql with qt....using following code :
#include"QApplication"
#include <QSqlDatabase>
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("mozart.konkordia.edu");
db.setDatabaseName("musicdb");
db.setUserName("gbatstone");
db.setPassword("T17aV44");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (!createConnection())
cout<<"error";
return app.exec();
}

but it gives the following error
fatal error: QSqlDatabase: No such file or directory
compilation terminated.


how to solve it.....
plz help

schnitzel
10th March 2011, 19:01
specify the following in your .pro file:



QT += sql