【问题标题】:QT5 error: Unknown type name 'QCoreApplication'. First program in Qt5QT5 错误:未知类型名称“QCoreApplication”。 Qt5 中的第一个程序
【发布时间】:2021-01-18 17:29:56
【问题描述】:

我刚刚在 Linux Ubuntu 20.04 LTS 中安装了 QTCreator,我点击了 File->New Project->Application->QTConsole Application。制作了 first.pro 文件和 main.cpp 文件。

first.pro 包含:

QT -= gui declarative
QT += widgets

CONFIG += c++11 console
CONFIG -= app_bundle

DEFINES += QT_DEPRECATED_WARNINGS


SOURCES += \
        main.cpp

qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.cpp 包含:

 #include <QCoreApplication>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    return a.exec();
}

错误出现在 QCoreApplication 行中。

【问题讨论】:

  • hangon - 你安装了qtcreator IDE?或整个 Qt 包 - 例如:qt.io/offline-installers ?
  • 意味着添加单击“Qt 5.x.x 离线安装程序链接”,然后选择 linux 主机。这会下载一个运行文件(你可以在命令行上运行)——它应该安装所有的库和你需要的一切(除了 gcc)。如果您只是安装 QtCreator,那么您可能缺少实际的 Qt 库......

标签: c++ user-interface qt5 qapplication qcoreapplication


【解决方案1】:

原因是 Ubuntu 20.04 上新版本的 Qtcreator 安装了clang-10,但它仍然需要clang-8

安装 clang-8 包:

apt install clang-8

【讨论】:

    【解决方案2】:

    如果错误是一个开放的红色圆圈,代码仍然会构建。

    如果您想摆脱打开的红色圆圈,请进入帮助->关于插件并取消选中 Clang 代码模型插件。然后重启 QT creator。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-20
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多