i'm starting to program in visual Studio C++ (2013) and i'm using Qt(5.5.0) for user interface . i'm trying to connect to my sql server database (sql server 2012) .
it should be simple based on documentation . this is my code :
#include "qt_test1.h"
//#include "ui_qt_test1.h"
#include <qmessagebox.h>
#include <qfiledialog.h>
#include <QtGui>
#include <QtSql\qsql.h>
#include <QtSql\qsqldatabase.h>
#include <QtSql\qsqlerror.h>
#include <qdebug.h>
qt_test1::qt_test1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
qt_test1::~qt_test1()
{
}
// when button clicked try to connect to database
void qt_test1::on_btnShowHello_clicked()
{
QSqlDatabase db = QSqlDatabase::addDatabase("mydb");
db.setDatabaseName("C:\\Program Files\\Microsoft SQL Server\\MSSQL11.MSSQLSERVER\\MSSQL\\DATA\\qt_test_db");
bool ok = db.open();
}
well when i try to debug i get this weird errorrs . its kind of missing dll thing which i dunno if its my code problem or qt installation error .
errors :
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSqlDatabase::~QSqlDatabase(void)" (__imp_??1QSqlDatabase@@QEAA@XZ) referenced in function "private: void __cdecl qt_test1::on_btnShowHello_clicked(void)" (?on_btnShowHello_clicked@qt_test1@@AEAAXXZ) E:\Project\qt_test1\qt_test1\qt_test1.obj qt_test1
Error 3 error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl QSqlDatabase::open(void)" (__imp_?open@QSqlDatabase@@QEAA_NXZ) referenced in function "private: void __cdecl qt_test1::on_btnShowHello_clicked(void)" (?on_btnShowHello_clicked@qt_test1@@AEAAXXZ) E:\Project\qt_test1\qt_test1\qt_test1.obj qt_test1
Error 4 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QSqlDatabase::setDatabaseName(class QString const &)" (__imp_?setDatabaseName@QSqlDatabase@@QEAAXAEBVQString@@@Z) referenced in function "private: void __cdecl qt_test1::on_btnShowHello_clicked(void)" (?on_btnShowHello_clicked@qt_test1@@AEAAXXZ) E:\Project\qt_test1\qt_test1\qt_test1.obj qt_test1
Error 5 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QSqlDatabase __cdecl QSqlDatabase::addDatabase(class QString const &,class QString const &)" (__imp_?addDatabase@QSqlDatabase@@SA?AV1@AEBVQString@@0@Z) referenced in function "private: void __cdecl qt_test1::on_btnShowHello_clicked(void)" (?on_btnShowHello_clicked@qt_test1@@AEAAXXZ) E:\Project\qt_test1\qt_test1\qt_test1.obj qt_test1
Error 6 error LNK2001: unresolved external symbol "__declspec(dllimport) public: static char * QSqlDatabase::defaultConnection" (__imp_?defaultConnection@QSqlDatabase@@2PEADEA) E:\Project\qt_test1\qt_test1\qt_test1.obj qt_test1
Error 7 error LNK1120: 5 unresolved externals E:\Project\qt_test1\x64\Debug\qt_test1.exe qt_test1