错误:QApplication:没有这样的文件或目录?

时间:2013-04-10 22:41:40

标签: c++ qt directory

我一直关注某人的Ytube Qt教程播放列表。当我尝试关注Basic Application and HTML Aware Widgets时,我在尝试使用添加的c ++类创建一个空的Qt项目时遇到此错误:

error: QApplication: No such file or directory

我安装了最新的Qt创建者和库,并强调了#includes ......

#include <QApplication>
#include <QLabel>

int main(int argc, char * argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("hello world");

    label.show();

    return app.exec();
}

回答如下:我试过了,我的.pro看起来像这样:

QT + =核心小部件 来源+ = main.cpp

我收到了这些错误..

In function 'int qMain(int, char**)':
error: request for member 'show' in 'label', which is of pointer type 'QLabel*' (maybe you meant to use '->' ?)

1 个答案:

答案 0 :(得分:2)

使用Qt5.0.1在KUbuntu上测试

我的.pro文件

QT      += core widgets
SOURCES += main.cpp

我的main.cpp文件:

#include <QApplication>
#include <QLabel>

int main(int argc, char * argv[])
{
    QApplication app(argc, argv);              // QApp... instead of Qapp...
    QLabel *label = new QLabel("hello world"); // QLabel * instead of Qlabel

    label->show();  // <- label-> instead of label.

    return app.exec();
}