Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136335

QGraphicsItem Destructor Causes App to Crash

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 4.8.x, 5.12, 6.9.0
    • Widgets: GraphicsView
    • Windows x64 either with VC/MinGW
    • Windows
    • Windows

    Description

      There is a big issue in Graphics View Framework of Qt. According to my research, it's been there since 4.8. The issue is if you delete any object derived from QGraphicsItem, the app crashes. I inspected the issue with a debugger and the reason seems paintEvent is still called after we removeItem from QGraphicsScene and delete it. Maybe there are paint messages left in the message queue, I haven't checked the internals tbh.

      Almost everyone who used QGraphicsView and QGraphicsScene encountered the same problem. You can verify with a simple search over the Internet. Some people found workarounds so that it trigger less frequently. These include calling either or both of these methods from QGraphicsItem subclasses before the destructor runs:

      removeFromIndex();
      prepareGeometryChange();

      Steps to Reproduce:

      • Create a QGraphicsScene and attach it to a QGraphicsView (setScene).
      • Create a subclass of QGraphicsItem which does some custom painting.
      • Put some logic to cause scene update() like a simple animation.
      • Call delete customGraphicsItemObj;
      • After a while your app will crash. It may not happen every time but frequent enough to reproduce.

      I have been using Qt for long time and this is the first time I saw a bug not solved for 10+ years. This makes Graphics View Framework effectively useless.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bibr Andreas Aardal Hanssen
            qui Gg Wp
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes