日安!
在Qt 4.7.3中,下面的示例在调用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;
}有什么想法吗?
更新:
已创建Bug report。
发布于 2011-11-01 10:19:24
当构造QGraphicsScene实例时,它会将自己附加到存储在单个QApplication实例的私有成员中的列表中,当删除它时,它也会将自己从该列表中删除:
QGraphicsScene::~QGraphicsScene()
{
Q_D(QGraphicsScene);
// Remove this scene from qApp's global scene list.
qApp->d_func()->scene_list.removeAll(this);
...
}当应用程序对象被销毁时,继承的基类的析构函数被递归调用,因此,~QApplication()调用~QCoreApplication(),后者本身调用~QObject()。
子对象的实际删除是在~QObject()中完成的。
这意味着在销毁scene对象时,所有QApplication成员都已销毁,因此~QGraphicsScene()在尝试访问列表时会崩溃。
https://stackoverflow.com/questions/7929981
复制相似问题