Segfault after QGraphicsView::paintEvent(QPaintEvent*)



  • Hi

    I have a class, which derives QGraphicsView. The class inherts the scene, which shall be painted.
    When I add a lot of objects in the scene and I can scale the view.

    So I get a segfault, if I do something in the view after adding a lot of new objects:

    @#0 0x0098a07a in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #1 0x00988bdc in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #2 0x00988c15 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #3 0x00988c58 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #4 0x00989453 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #5 0x0098c086 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #6 0x0098c2b3 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #7 0x00983dfc in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #8 0x009a0360 in QGraphicsView::paintEvent(QPaintEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #9 0x0031d152 in QWidget::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #10 0x0073ae55 in QFrame::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #11 0x007cdab1 in QAbstractScrollArea::viewportEvent(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #12 0x009a16ac in QGraphicsView::viewportEvent(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #13 0x007d01d6 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #14 0x00dd7b16 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #15 0x002c2ea2 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #16 0x002c83a2 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #17 0x00dd797e in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #18 0x00318ada in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #19 0x00511d4b in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #20 0x0030e9db in QWidgetPrivate::syncBackingStore() () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #21 0x0031dae7 in QWidget::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #22 0x002c2ed4 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #23 0x002c83a2 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #24 0x00dd797e in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #25 0x00ddbad8 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #26 0x00ddbe0c in QCoreApplication::sendPostedEvents(QObject*, int) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #27 0x00978396 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #28 0x009784db in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #29 0x00de9c01 in QMetaCallEvent::placeMetaCall(QObject*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #30 0x00df2c7b in QObject::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #31 0x0097f1e0 in QGraphicsScene::event(QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #32 0x002c2ed4 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #33 0x002c830d in QApplication::notify(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #34 0x00dd797e in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #35 0x00ddbad8 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #36 0x00ddbe0c in QCoreApplication::sendPostedEvents(QObject*, int) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #37 0x00e0a494 in ?? () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #38 0x012d4d86 in g_main_context_dispatch () from /lib/i386-linux-gnu/libglib-2.0.so.0
    #39 0x012d5125 in ?? () from /lib/i386-linux-gnu/libglib-2.0.so.0
    #40 0x012d5201 in g_main_context_iteration () from /lib/i386-linux-gnu/libglib-2.0.so.0
    #41 0x00e0a887 in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #42 0x0037baaa in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #43 0x00dd650d in QEventLoop::processEvents(QFlagsQEventLoop::ProcessEventsFlag) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #44 0x00dd67a9 in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #45 0x00ddbeba in QCoreApplication::exec() () from /usr/lib/i386-linux-gnu/libQtCore.so.4
    #46 0x002c0a74 in QApplication::exec() () from /usr/lib/i386-linux-gnu/libQtGui.so.4
    #47 0x080505ff in main ()
    @

    "Doing something" means something like scale in and scale out or translate the view.
    I happens only, when the view is scaled. So if I add 1000 object in a unscaled view, it works without any problems.

    I have no idea, where what I can do to prevent crashing. Any idea?



  • I found out the problem, but cannot solve it:

    I have following code:
    @ qDebug() << "Before removing: " << scene->items().count() << preview_matrix_points.count();
    for(int i=0;i<preview_matrix_points.count();i++) {
    scene->removeItem(preview_matrix_points.at(i));
    //delete preview_matrix_points.at(i);
    }
    preview_matrix_points.clear();

    qDebug() << "After Removing" << scene->items().count();@
    

    I delete a lot of objects:

    Before removing: 130 119
    After Removing 11

    That is okay... BUT: The objects are removed in the scene, but not in the view. Some of the objects will be still painted even if they should not be anymore in the scene. They lost all signal/slot connections. How is that possible? How can I remove these objects from the GraphichsScene?

    I also set the scene of the view to NULL and set it back to the scene, but the points in there are still painted. So the object have to be in the scene. That's vodoo for me. If scene of the view is NULL, then the lost QGraphicsObject is not there. So it have to be in the scene.

    Any idea how to remove it really?



  • seems to be a bigger problem I guess.
    I did now a really dirty work-around, but it is not a solution of the problem. Any idea, how to fix it?


  • Moderators

    maybe thats not a solution to your problem but worth a try:
    QGraphicsView::setViewportUpdateMode(QGraphicsView::FullViewportUpdate)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.