PDA

View Full Version : Segmentation Fault on when trying to construct QApplication



tarahSky
27th July 2012, 15:11
Hi,

I am a complete beginner in Qt. I have just installed Qt, and tried to run a simple hello world application:

#include <QApplication>
#include <QPushButton>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton hello("Hello World");
hello.resize(100,30);
hello.show();
return app.exec();

}

I have compiled it by doing the following:

qmake -project
qmake
make

The project compiles fine, but when I try to run it I get a segmentation fault.

If I replace the QApplication above with QCoreApplication, it works.

Can anyone tell me why this error might be occurring?
(As far as I can see, it is linking with -lQtGui fine).

wysota
27th July 2012, 18:48
Are you running the application with a user that has access to the X server (i.e. not as root)?

tarahSky
28th July 2012, 05:53
Yes, I am running the program with a standard user.

tarahSky
28th July 2012, 09:18
When I create a QtWidget application using QtCreator, and have exactly the same code. I can build and run it fine.

So it seems that the problem is with qmake when I try to compile it from the terminal.

If I create a project file called hello.pro using QtCreator, and have the file hello.cpp with the above code, if I build it using qmake, make (instead of QtCreator) it gives a segmentation fault.

But if I build it in QtCreator it will work fine.

Does anyone know why this may be occurring? Are there options that need to be specified to qmake or make?

Added after 16 minutes:

Hi, I found the solution to the problem.

In my .bashrc I had the PATH variable as:

export PATH=$PATH:/opt/QtSDK/Desktop/Qt/474/gcc/bin:/opt/QtSDK/QtCreator/bin

instead of

export PATH=/opt/QtSDK/Desktop/Qt/474/gcc/bin:/opt/QtSDK/QtCreator/bin:$PATH

so it was using the version of qmake in /usr/bin which was for Qt 4.3.4

instead of the version in

/opt/QtSDK/Desktop/Qt/474/gcc/bin

which was for version Qt 4.7.4.

Once I changed it around, it accessed the right version of qmake, and worked fine.