Results 1 to 5 of 5

Thread: Creating an object of QGraphicsScene results in segmentation fault

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Creating an object of QGraphicsScene results in segmentation fault

    I created a new Qt 5 project with QtCreator, and added the following lines to it.

    #include <QGraphicsScene>

    // in main():
    QGraphicsScene scene;

    In the .pro file I added:
    Qt += gui

    The object creation of QGraphicsScene is resulting in the segmentation fault. What point am I missing?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Creating an object of QGraphicsScene results in segmentation fault

    This works without issue Qt 5.2, GCC 4.7 on Linux:
    Qt Code:
    1. #include <QApplication>
    2. #include <QGraphicsScene>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6. return 0;
    7. }
    To copy to clipboard, switch view to plain text mode 
    The QApplication must exist before the scene or it seg faults here too.

  3. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Creating an object of QGraphicsScene results in segmentation fault

    Thanks for respondng.


    I realized now that instead of QApplication my rest of the program is using QtGui/QGuiApplication.

    How to use QGraphicsScene with QtGui/QGuiApplication?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Creating an object of QGraphicsScene results in segmentation fault

    You can't. QGraphicsScene is part of QtWidgets and intimately connected to a full QApplication instance.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Creating an object of QGraphicsScene results in segmentation fault

    And you will also need
    Qt Code:
    1. QT += widgets
    To copy to clipboard, switch view to plain text mode 
    to add the widget library

    Cheers,
    _

Similar Threads

  1. Creating an object of QDeclarativeView results in segmentation fault
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 8th October 2013, 11:38
  2. Replies: 21
    Last Post: 28th September 2010, 10:59
  3. Replies: 15
    Last Post: 26th October 2009, 18:47
  4. Segmentation fault when creating new QString
    By di_zou in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 18:07
  5. QGraphicsScene segmentation fault
    By maxpower in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2006, 18:28

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.