Results 1 to 4 of 4

Thread: Segmentation Fault on when trying to construct QApplication

  1. #1
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Segmentation Fault on when trying to construct QApplication

    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).

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Segmentation Fault on when trying to construct QApplication

    Are you running the application with a user that has access to the X server (i.e. not as root)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Segmentation Fault on when trying to construct QApplication

    Yes, I am running the program with a standard user.

  4. #4
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Segmentation Fault on when trying to construct QApplication

    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.
    Last edited by tarahSky; 28th July 2012 at 09:18.

Similar Threads

  1. Replies: 21
    Last Post: 28th September 2010, 10:59
  2. Random Segmentation Fault on QApplication constructor
    By Mankin in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 2nd October 2009, 18:54
  3. Replies: 0
    Last Post: 20th April 2009, 17:45
  4. Must construct QApplication before QPaintDevice
    By sekatsim in forum Qt Programming
    Replies: 16
    Last Post: 8th June 2008, 00:00
  5. Replies: 15
    Last Post: 21st April 2007, 17:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.