c++ - Qt LNK2019 基本 Qt5 应用程序错误

标签 c++ qt compiler-errors qt5 lnk2019

我正在尝试按照在线教程学习 Qt5 和 QtCreator 2.6.1

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

#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

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

最佳答案

这是一个无法将目标文件链接在一起的链接器错误, 首先删除所有 build 目录,然后检查此行是否已添加到您的 .pro 文件中:

QT += core gui widgets

这应该可行,如果再次失败,您必须提供有关您的编译器及其搜索路径的更多信息,并在此处发布您的.pro文件内容。

关于c++ - Qt LNK2019 基本 Qt5 应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14667011/

相关文章:

c++ - 在不调用 setSizeIcon() 的情况下动态调整 QIcon 的大小

qt - QBackingStore::endPaint() 在 backingstore 绘制设备上使用事件绘制器调用

c++ - 在 Qt C++ 中的自定义项委托(delegate)上绘制文本时的性能问题

c++ - 得到这个错误: request for member 'at' in 'array3' , which is of pointer type

visual-studio - 样本数据编译错误

compiler-errors - 如何使用 Ord::max 函数?

c++ - Opengl macOS 失败

c++ std::getline/std::sort 没有按预期工作

c++ - 隐藏第三方C++头文件的内容

c++ - 在 Windows 10 上从源代码编译 libcurl 7.61.1