Set up QSqlDatabase : QSqlDatabase « Qt « C++






Set up QSqlDatabase

  
#include <QtGui>
#include <QtSql>
#include <QDebug>

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);

  QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
  db.setHostName("url.example.com");
  db.setDatabaseName("databaseName");
  db.setUserName("user");
  db.setPassword("pass");

  if (!db.open()) {
     qDebug() << db.lastError();
     return1;
  }

   
    
  








Related examples in the same category

1.Connect to MySql with QSqlDatabase, and do select, update, insert and delete
2.Operate Sqlite database with QSqlDatabase
3.Using sql database from Qt
4.Prepared statement