Important: Please read the Qt Code of Conduct -

Segmentation fault in QGraphicsView::setScene()

  • Hello forum

    I have a normal widget application which should show a finite automata in a graphic view widget. I add a QGgraphicsView to the main window, which has an instance of QGraphicsScene:
    MainWindow::MainWindow(QWidget *parent) :
    scene(new QGraphicsScene(this))
    ui->graphicsView->setScene(scene); // bumb!
    Program crashes by a segmentation fault when it tries to set scene for graphicsView.

  • @
    wild pointer?

  • scene is just constructed in initialization list using new operator. So I trust the new operator won't screw it up.
    @ui->graphicsView->setScene(scene); // bumb!@

    Looking at the above line - could be because of either 'ui' or 'graphicsView' - may be not a valid pointer?

  • Since you didn't include the class definition, mine is just a guess but try deleting ui-> or replacing it with this->
    leave just
    @graphicsView->setScene(scene);@ and see if it work (it should ;) )

  • Or may be try clean and build or rebuild.

Log in to reply