2013-05-14 99 views
0

我试图编译下面的代码中的Qt 5.0.0:QSqlDatabase LNK2019错误

#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(); 
} 

,我收到此错误:

main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QStringList __cdecl QSqlDatabase::drivers(void)" ([email protected]@@[email protected]@XZ) referenced in function _main

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

我在.pro添加QT += sql。有什么问题?

回答

3

您应该添加QtSql.lib(你可以找到Qtsql在你的电脑恰好QT/lib目录的名称)通过转到项目/属性/配置属性/链接器/输入,添加QtSql.lib附加依赖​​

附:我曾经面对这个错误,并通过这种方式解决了错误。祝你好运