Qt – Simple Qt program builds but doesn’t show output

qt

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.

Update

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.

Best Answer

If you want a QLabel to display, you need to run the GUI application class QApplication, not QCoreApplication.

Related Topic