c++ - Qt 5 构建错误 : extra characters after test expression

标签 c++ qt qt5

我正在尝试学习 Qt 5.3,这是我的第一个程序(hello world)。当我尝试构建时,它显示此错误:

extra characters after test expression.

我完全不明白为什么会出现这个错误。我只是从网上拿了一些简单的代码来检查我是否正确安装了Qt。 代码如下:

#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv)
{
    QApplication app (argc, argv);
    QPushButton button ("Hello world !");
    button.show();
    return app.exec();
}

错误显示在第 3、5、6、8 行。 我对Qt完全陌生,所以请给一个简单的解释。

最佳答案

检查 .pro 文件。有时是因为你没有在最后一行的末尾没有黑斜线:

HEADERS += Qt/mainwindow.h \
    Qt/MPrintableWidget.h \
    Qt/MPrintableWidgetGroup.h    # Oooops forgot the \ here
    Qt/MFixedSizeDialog.h \
    Qt/MScreenPage.h

这里的每一行除了最下面的一行都需要以反斜杠结尾。

关于c++ - Qt 5 构建错误 : extra characters after test expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24981050/

相关文章:

使用 vector 重载 << 时的 C++ 错误

c++ - 使用自定义 DirectShow 过滤器(DLL,已注册)

c++ - 将现有的 QTcpSocket 变形为 QSslSocket

qt - 如何在QML中声明列表属性

qt - 什么影响 QLCDNumber 数字的可见性?

c++ - 返回匿名结构

c++ - OpenCV - 用于边缘图(不是轮廓)的 approxPolyDP

qt - 按住Qml MouseArea移动窗口

C++类静态成员初始化

c++ - 如何在 MSYS2 中通过 CMake 构建 C++ Qt5 应用程序