QGraphicsScene::~QGraphicsScene() segmentation fault

倖福魔咒の 提交于 2019-12-22 09:39:34

问题


Good day!

With Qt 4.7.3 an example below crashes at QGraphicsScene::~QGraphicsScene() call:

#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:

Bug report created.


回答1:


When a QGraphicsScene instance is constructed it appends itself in a list stored in a private member of the single QApplication instance, and when it is deleted, it also remove itself from that list:

QGraphicsScene::~QGraphicsScene()
{
    Q_D(QGraphicsScene);

    // Remove this scene from qApp's global scene list.
    qApp->d_func()->scene_list.removeAll(this);

    ...
}

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

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



来源:https://stackoverflow.com/questions/7929981/qgraphicssceneqgraphicsscene-segmentation-fault

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!