Qt supports ODBC, to connect to the odbc database using, QSqlDatabaseyou can use the following code
QString connectionTemplate = "DRIVER={SQL SERVER};SERVER=%1;DATABASE=%2;";
QString connectionString = connectionTemplate.arg(server).arg(dbName);
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", connectionName);
db.setDatabaseName(connectionString);
db.setUserName(user);
db.setPassword(password);
if (db.open())
{
}
else
{
}
Most or all of the QSql classes ... return an error, it is a very good habit to always check for this error.
If you built Qt from scratch, you might have to enable odbc plugin building
source
share