I'm trying to connect with a database created with Microsoft Sql Express 2012. I'm using qt 5.2.1, and at the end of the connection implementetion I write some code to have a validation. But an error accure, and I don't know why. The program is structured in this way:

-in the MainWindow of qt GUI application there is a Button, if you click on this Button you open a Dialog Application. -in the Dialog Application is devolped the connection.

here the .h code of the Dialog Application:
Qt Code:
  1. #ifndef DATABASE_H
  2. #define DATABASE_H
  3.  
  4. #include <QDialog>
  5.  
  6. namespace Ui {
  7. class DataBase;
  8. }
  9.  
  10. class DataBase : public QDialog
  11. {
  12. Q_OBJECT
  13.  
  14.  
  15.  
  16. public:
  17. explicit DataBase(QWidget *parent = 0);
  18. ~DataBase();
  19.  
  20. private:
  21. Ui::DataBase *ui;
  22. };
  23.  
  24. #endif // DATABASE_H
To copy to clipboard, switch view to plain text mode 

here the relative .cpp code of Dialog Application:

Qt Code:
  1. #include <database.h>
  2. #include <ui_database.h>
  3. #include <QtSql>
  4. #include <QtDebug>
  5. #include <iostream>
  6. DataBase::DataBase(QWidget *parent) :
  7. QDialog(parent),
  8. ui(new Ui::DataBase)
  9. {
  10.  
  11. QString servername="MARCO-VAIO";
  12. QString dbname="IfaCOM";
  13. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
  14. db.setConnectOptions();
  15. QString dsn = QString("DRIVER={SQL Native Client}; SERVER=%1; DATABASE=%2;TRUSTED_CONNECTION=Yes;").arg(servername).arg(dbname);
  16. db.setDatabaseName(dsn);
  17. if(db.open()){
  18. ui->label->setText("Connected....");
  19. }
  20.  
  21.  
  22. }
  23.  
  24. DataBase::~DataBase()
  25. {
  26. delete ui;
  27. }
To copy to clipboard, switch view to plain text mode 

and here the error that accured:
Cattura.JPG

Please check this issue...thanks in advance.