Error QGraphicsScene :: ~ QGraphicsScene ()

Good afternoon!

As of Qt 4.7.3, the following is an example of a failure when calling QGraphicsScene :: ~ QGraphicsScene ():

#include <QCoreApplication> #include <QGraphicsScene> int main( int argc, char* argv[] ) { // replace this with QObject app; and no problems QCoreApplication app( argc, argv ); new QGraphicsScene( &app ); return 0; } 

Any ideas?

UPDATE:

Error report created.

+3
source share
1 answer

When a QGraphicsScene instance is created, it is added to the list stored in the private member of a single QApplication instance, and when it is deleted, it is also removed from this list:

 QGraphicsScene::~QGraphicsScene() { Q_D(QGraphicsScene); // Remove this scene from qApp global scene list. qApp->d_func()->scene_list.removeAll(this); ... } 

When the application object is destroyed, the destructors of the inherited base class are called recursively, so ~QApplication() calls ~QCoreApplication() , which itself calls ~QObject() .

Actual deletion of child objects is done in ~QObject() .
Which means that when the scene object is destroyed, all QApplication members are already destroyed, so ~QGraphicsScene() crashes when it tries to access the list.

+2
source

Source: https://habr.com/ru/post/982021/


All Articles