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()
{
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[])
{
if (!createConnection())
{
QMessageBox::information(0,
"Error",
"Database not openned" );
return 1;
}
else
QMessageBox::information(0,
"All fine",
"Database openned" );
}
return a.exec();
}
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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks