سؤال

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?

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top