View Full Version : Drive sql
lucasbemo
3rd November 2010, 13:38
Hi,
How do I get driver to connect my QT application with a database (preferably MySql) ?
I really can not find. : /
Tks.
tbscope
3rd November 2010, 13:48
http://doc.qt.nokia.com/4.7/qt-sql.html
Aleksandar
3rd November 2010, 14:18
Here are SQL drivers:
C:\Qt\2010.05\qt\plugins\sqldrivers\
You should copy dll files from this folder in to C:\...\project_name-build-desktop\sqldrivers
You will probably also need some dll files from the folder:
C:\Qt\2010.05\qt\bin\
Don't forget to write Qt += core sql into .pro file
Here is an example:
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "DatabaseName");
db.setHostName("HostName");
db.setDatabaseName("Database_ODBC_Name");
db.setUserName("user");
db.setPassword("password");
bool status;
status = db.open();
return status;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
if (!createConnection())
{
QMessageBox::information(0, "Error", "Database not openned" );
return 1;
}
else
QMessageBox::information(0, "All fine", "Database openned" );
}
return a.exec();
}
lucasbemo
4th November 2010, 18:33
tbscope and Aleksandar thanks (obrigado).
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.