0

I am trying to connect to SQL Server 2008R2 with my qt application in windows but I am getting errors. Here's what I am doing:

#include "ui_test1.h";
#include "QtSql/QtSql";

void Test1::on_btnsnd_clicked()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("ODBC");

    db.setHostName("ITPL_PC1");
    db.setDatabaseName("Test");
    db.setUserName("sa");
    db.setPassword("insforia");
    db.open();
    QSqlQueryModel *model = new QSqlQueryModel;

    QString query = "insert into qttable(PID) values('ARUP')";
    model->setQuery(query, db);

    db.close();
}

i am getting this error 27 times :

 test1.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport)        public: __thiscall QSqlDatabase::~QSqlDatabase(void)" (__imp_??1QSqlDatabase@@QAE@XZ) referenced in function "private: void __thiscall Test1::on_btnsnd_clicked(void)" (?on_btnsnd_clicked@Test1@@AAEXXZ)

I don't know how to do this (I found this in google.)

What should I do to fix it?

2
  • What errors do you get? What do QSqlDatabase::lastError() and QSqlQueryModel::lastError() say? Commented Jan 25, 2013 at 12:57
  • i am getting this error when i am running the app test1.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QSqlDatabase::~QSqlDatabase(void)" (__imp_??1QSqlDatabase@@QAE@XZ) referenced in function "private: void __thiscall Test1::on_btnsnd_clicked(void)" (?on_btnsnd_clicked@Test1@@AAEXXZ) Commented Jan 25, 2013 at 13:00

1 Answer 1

1

If you use MSVC, you should add %QTDIR%/lib/QtSql4.lib to Release configuration of your project and %QTDIR%/lib/QtSqld4.lib to Debug one. You should change 4 in file names to 500, if you use Qt 5.0. So, file names would be %QTDIR%/lib/QtSql500.lib and %QTDIR%/lib/QtSqld500.lib

Project Properties


If you use QtCreator you should add the next line into your .pro file

QT += sql

Upd: added description for QtCreator's .pro file

Sign up to request clarification or add additional context in comments.

4 Comments

how to find this window... sorry i am very new to qt
in my .pro file i have added like this : LIBS += "C:\Qt\4.8.4\lib\QtSql4.lib"; LIBS += "C:\Qt\4.8.4\lib\QtSqld4.lib"; now i am getting an error :-1: error: LNK1104: cannot open file 'C:\Qt\4.8.4\lib\QtSql4.lib;'
You can simple add this line: QT += sql to .pro file. And remove that LIB lines. P.S. Sorry, but you didn't tell aboud IDE you used. I thought that it's MSVC. Now I see, that it's QtCreator.... I'll edit answer
ok i solved that, sorry for not telling that.. and thanks for the solution .. but i am facing another problem regarding this can just take a look at that ... here's the link link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.