Qt create and QLabel, why is there an error?

Simplicity picture Simplicity · Apr 1, 2011 · Viewed 9.9k times · Source

I'm using Qt creator 2.0.1, and when entering this line:

#include <QLabel>

I get the following error:

QLabel: No such file or directory

Why is that? And, how can I include a label in this case?

UPDATE

@maverik showed me how to solve the QLabel error, but I'm now getting this error:

enter image description here

The program I'm trying to run is:

#include <QtCore/QCoreApplication>
#include <QtGui/QLabel>

int main(int argc, char *argv[]) {
QCoreApplication myapp(argc, argv);
QLabel *label = new QLabel("Hello");
label->show();
return myapp.exec(); 
}

Any ideas?

Thanks.

Answer

snoofkin picture snoofkin · Apr 1, 2011

Use

QApplication

Rather than

QCoreApplication

.

from the QCoreApplication docs:

The QCoreApplication class provides an event loop for console Qt applications. This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one QCoreApplication object. For GUI applications, see QApplication.

Then Include the relevant headers, and it will compile just fine. QCoreApplication is for non-Gui applications (Console).