J L
J L

Reputation: 367

error: QApplication: No such file or directory?

I've been following someone's Youtube playlist of tutorials for Qt. When I try to follow the Basic Application and HTML Aware Widgets, I am getting this error when trying create an empty Qt project with an added c++ class:

error: QApplication: No such file or directory

I have the latest Qt creator and library installed and its underlining the #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();
}

to answer below: I tried that, my .pro looks like this:

QT += core widgets SOURCES += main.cpp

and I got these errors..

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

Upvotes: 0

Views: 7721

Answers (1)

gongzhitaao
gongzhitaao

Reputation: 6682

Tested on KUbuntu with Qt5.0.1

My .pro file

QT      += core widgets
SOURCES += main.cpp

My main.cpp file:

#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();
}

Upvotes: 2

Related Questions