0

I tried to compile the following code in Qt 5.0.0:

#include <QApplication>
#include <QtSql/QSql>
#include <Qtsql/QSqlDatabase>
#include <QStringList>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QStringList db = QSqlDatabase::drivers();
    return a.exec();
}

and I received this error:

main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QStringList __cdecl QSqlDatabase::drivers(void)" (__imp_?drivers@QSqlDatabase@@SA?AVQStringList@@XZ) referenced in function _main

debug\test.exe:-1: error: LNK1120: 1 unresolved externals

I have added QT += sql in my .pro. What's the problem?

Antti29
  • 2,953
  • 12
  • 34
  • 36
Aidin.T
  • 731
  • 3
  • 10
  • 25

1 Answers1

3

You should add QtSql.lib ( you can find the name of Qtsql exactly in QT/lib in your computer) by go to Project/Properties/Configuration properties/Linker/Input, add QtSql.lib to Additional Dependencies

P.S. I used to face this error, and the error is fixed by this way. Good luck

Patt Mehta
  • 4,110
  • 1
  • 23
  • 47
ndnguyen
  • 140
  • 1
  • 11