4

我正在尝试在线学习教程并使用 QtCreator 2.6.1 学习 Qt5

但是,我尝试按照本教程编写一个基本应用程序,但每当我尝试构建项目时,我都会收到链接错误:

#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello World");
    label->show();

    return app.exec();
}

单击“构建”后,我会收到大约 50 个错误,结果类似于以下内容:

main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (__imp_?exec@QApplication@@SAHXZ) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWidget::show(void)" (__imp_?show@QWidget@@QAEXXZ) referenced in function _main

有没有办法通过链接库等来解决这个问题(假设它们没有正确链接)?如果没有,我还能做些什么来尝试解决这个问题?

4

1 回答 1

6

this a linker fault that can't link object files together, first delete all the build directory, then check that this line was added to your .pro file:

QT += core gui widgets

this should work, if gets fail again, you must give more information about your compiler and their search path, plus post your .pro file content here.

于 2013-02-03T11:15:17.470 回答