Reputation: 273
I have just started learning Qt and tried to compile and run a simple program of hello world. The program builds without any issues and gives this output in compiler output
Starting: /qtbuild/bin/qmake /home/ved/Qt/train1/train1.pro -spec /qtbuild/mkspecs/qws/linux-arm-g++ -r CONFIG+=debug Exited with code 0. Starting: /usr/bin/make -w make: Entering directory `/home/ved/Qt/train1' make: Nothing to be done for `first'. make: Leaving directory `/home/ved/Qt/train1' Exited with code 0.
but on trying to run the program, it only displays this:
Starting /home/ved/Qt/train1/train1... /home/ved/Qt/train1/train1 exited with code 255
My code:
#include #include int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QLabel *label = new QLabel("Hello World!!!"); label->show(); return a.exec(); }
I am completely new to Qt building procedure and can't understand what is wrong.
tried changing QCoreApplication
to QApplication
. No change.
Running build steps for project train1... Starting: /qtbuild//bin/qmake /home/ved/Qt/train1/train1.pro -spec /qtbuild/mkspecs/qws/linux-arm-g++ -r CONFIG+=debug Exited with code 0. Starting: /usr/bin/make -w make: Entering directory `/home/ved/Qt/train1' arm-linux-g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/qtbuild/mkspecs/qws/linux-arm-g++ -I. -I/qtbuild/include/QtCore -I/qtbuild/include/QtNetwork -I/qtbuild/include/QtGui -I/qtbuild/include -I. -I/usr/local/tslib-arm/include -o main.o main.cpp In file included from /qtbuild/include/QtCore/qobject.h:48, from /qtbuild/include/QtCore/qiodevice.h:46, from /qtbuild/include/QtCore/qxmlstream.h:45, from /qtbuild/include/QtCore/QtCore:3, from main.cpp:1: /qtbuild/include/QtCore/qstring.h:91: note: the mangling of 'va_list' has changed in GCC 4.4 arm-linux-g++ -Wl,-rpath,/qtbuild/lib -o train1 main.o -L/usr/local/tslib-arm/lib -L/qtbuild//lib -lQtGui -L/qtbuild//lib -L/usr/local/tslib-arm/lib -lQtNetwork -lQtCore -lpthread make: Leaving directory `/home/ved/Qt/train1' Exited with code 0.
I use Qt 4.6.3.
Upvotes: 1
Views: 7048
Reputation: 607
I having the same problem. Let it to be restart QT. Surely it works
Upvotes: 0
Reputation: 3493
You should tell Qt, that you want to build project with GUI. Open your's project .pro file and change line
QT += ...
to
QT += core gui
example, .pro file:
QT += core gui
TARGET = untitled1
TEMPLATE = app
SOURCES += main.cpp
main.cpp:
#include <QtGui/QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel lbl("hello world");
lbl.show();
return a.exec();
}
Upvotes: 2
Reputation: 9014
You must set in project configuration that you are compiling Qt GUI application. Using of QApplication instead QCoreApplication is not enough. I don't know your IDE, so i can't provide "howto" - but i belive that you will easly find necessary options. For eapmle, in MSVC, you set neccessary application type (console or GUI) during creation of a project.
Also - exit code 255 shows on some error. Exit code must be zero, exept cases, when you manually change it.
Upvotes: 0
Reputation: 4360
If you want a QLabel to display, you need to run the GUI application class QApplication
, not QCoreApplication
.
Upvotes: 2
Reputation: 370
change QCoreApplication
to QApplication
an add a Main Window
QApplication a(argc, argv);
QMainWindow* mainWin = new QMainWindow();
QLabel *label = new QLabel(mainWin, "Hello World!!!");
mainWin->setCentralWidget(label);
mainWin->show();
Upvotes: 0
Reputation: 90843
You need to create a window if you want to display a label. Basically something like this (not tested):
QMainWindow* win = new QMainWindow();
QLabel *label = new QLabel(win, "Hello World!!!");
label->show();
win->show();
Upvotes: 0