我有一个QGraphicsScene,我正在添加一个名为BorderRect的子类QGraphicsRectItem,它指示了sceneRect的边界。 BorderRect具有允许用户更改其大小的夹点,然后更改场景的sceneRect。所有这一切都有效,除了每隔一段时间它就会导致一个seg故障,后面的跟踪如下:
#0 _int_malloc (av=0x7ffff587e620, bytes=32) at malloc.c:3415
#1 0x00007ffff55592a4 in *__GI___libc_malloc (bytes=32) at malloc.c:2924
#2 0x00007ffff5e4c40d in operator new(unsigned long) () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6
#3 0x00007ffff723911e in QRegion::QRegion(QRect const&, QRegion::RegionType) () from /usr/lib64/qt4/libQtGui.so.4
#4 0x00007ffff72394de in QRegion::intersect(QRect const&) const () from /usr/lib64/qt4/libQtGui.so.4
#5 0x00007ffff7239509 in QRegion::operator&(QRect const&) const () from /usr/lib64/qt4/libQtGui.so.4
#6 0x00007ffff723952f in QRegion::operator&=(QRect const&) () from /usr/lib64/qt4/libQtGui.so.4
#7 0x00007ffff70e0c6b in QWidgetPrivate::subtractOpaqueSiblings(QRegion&, bool*, bool) const ()
from /usr/lib64/qt4/libQtGui.so.4
#8 0x00007ffff72b6141 in QWidgetPrivate::scrollRect(QRect const&, int, int) () from /usr/lib64/qt4/libQtGui.so.4
#9 0x00007ffff712fe8a in QWidgetPrivate::scroll_sys(int, int) () from /usr/lib64/qt4/libQtGui.so.4
#10 0x00007ffff70eefe5 in QWidget::scroll(int, int) () from /usr/lib64/qt4/libQtGui.so.4
#11 0x00007ffff76b7fbb in QGraphicsView::scrollContentsBy(int, int) () from /usr/lib64/qt4/libQtGui.so.4
#12 0x00007ffff6b7c0fa in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) ()
from /usr/lib64/qt4/libQtCore.so.4
#13 0x00007ffff770ec7e in QAbstractSlider::valueChanged(int) () from /usr/lib64/qt4/libQtGui.so.4
#14 0x00007ffff76b0dca in QGraphicsViewPrivate::recalculateContentSize() () from /usr/lib64/qt4/libQtGui.so.4
#15 0x00007ffff76bab39 in ?? () from /usr/lib64/qt4/libQtGui.so.4
#16 0x00007ffff6b7c0fa in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) ()
from /usr/lib64/qt4/libQtCore.so.4
#17 0x00007ffff7687a45 in QGraphicsScene::sceneRectChanged(QRectF const&) () from /usr/lib64/qt4/libQtGui.so.4
#18 0x000000000042fef0 in BorderRectItem::sceneEventFilter (this=0xfc0070, watched=0xef6e80, event=0x7fffff800590)
at gui/BorderRectItem.cpp:193
...
还有几行,但是后面跟踪的第18行引用的行对应于调用setSceneRect,其中QRectF对应于BorderRect的新维度,在这种情况下:
{xp = 20, yp = -59, w = 563.94193411401511, h = 436.5631806793956}
我不知道为什么会崩溃。我检查了场景,它不是空的。我怀疑这将是非常难以调试的,我真正感兴趣的是如何去做这个的提示。特别是,当我在后向跟踪中上下移动时,检查Qt代码中的变量状态真的很有帮助,我不知道该怎么做。我正在运行Linux ...我可以用调试符号或其他东西重建Qt吗?
答案 0 :(得分:1)
只是在这里猜测,但是这个堆栈跟踪让我怀疑,你从某些自己的方法返回对本地堆栈QRect的引用,或引用其他一些堆栈变量(甚至是指向堆栈的显式指针)变量,但事故更难做到。)
是的,您可以使用调试符号编译Qt,请参阅: