Hello all .. i'm a new one to qt
i needed to connect qt with a database system
so i used the following code

Qt Code:
  1. #include <QtCore/QCoreApplication>
  2. #include <QtSql>
  3. #include <QDebug>
  4.  
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QCoreApplication a(argc, argv);
  9.  
  10. QString serverName = "LOCALHOST\\SQLEXPRESS";
  11. QString dbName = "test";
  12. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
  13. db.setConnectOptions();
  14. QString dsn = QString("DRIVER={SQL Server Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(serverName).arg(dbName);
  15. db.setDatabaseName(dsn);
  16.  
  17.  
  18. if(db.open())
  19. {
  20. qDebug()<<"Opened!";
  21. }
  22. return a.exec();
  23. }
To copy to clipboard, switch view to plain text mode 

with following in .pro file

Qt Code:
  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2012-01-14T12:52:43
  4. #
  5. #-------------------------------------------------
  6.  
  7. QT += core
  8. QT += sql
  9. QT -= gui
  10.  
  11. TARGET = DB
  12. CONFIG += console
  13. CONFIG -= app_bundle
  14.  
  15. TEMPLATE = app
  16.  
  17.  
  18. SOURCES += main.cpp
To copy to clipboard, switch view to plain text mode 

i've passed thorught many articles and threads and unfortunately no result
some of them suggested to add sqldriver folder in my application directory it didn't work
and some of them suggested to compile the odcb driver library but i faced a compliation problem (by both GUI & command line)

any solutions please ...