Qt Sql Databse Connection

Sql Database Connection code snippet

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("HOST_NAME");
db.setDatabaseName("database_name");
db.setUserName("db_user");
db.setPassword("db_password");
bool ok = db.open();if(ok){
    // Houston we have connection!
}

In order this to work you have to create ODBC connection in

Control Panel/Administrative Tools/ODBC Data Source Administrator/System DSN/Add...
Tagged with: , ,
Posted in QT

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Sites
Categories
Archives