QGraphicsScene::~QGraphicsScene() 分段错误

发布于 2024-12-12 21:47:40 字数 480 浏览 2 评论 0原文

再会!

对于 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;
}

有什么想法吗?

更新:

已创建错误报告

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总攻大人 2024-12-19 21:47:40

当构建 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(),而~QCoreApplication()本身又调用~QObject()

子对象的实际删除是在~QObject()中完成的。
这意味着在场景对象被销毁时,所有QApplication成员都已被销毁,因此~QGraphicsScene()在尝试访问列表时崩溃。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文