Reputation: 48916
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:
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.
Upvotes: 3
Views: 11179
Reputation: 11
QLabel Class The QLabel widget provides a text or image display. More...
Header: #include qmake: QT += widgets Inherits: QFrame List of all members, including inherited members Obsolete members
*** Simply add QT += widgets to the .pro
Upvotes: 0
Reputation: 48916
I think I found where the issue is.
Since I'm using Qt Creator
, and when creating a new project, I was choosing Qt Console Application
instead of Qt Gui Application
.
Upvotes: 0
Reputation: 8895
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).
Upvotes: 5
Reputation: 999
Check that your Qt project -file contains
QT += gui
CONFIG += qt
and does not contain
QT -= gui
I think this causes the linking problem. Also I think
#include <QLabel>
... should be enough if project file is correct.
Upvotes: 2