Qt4-preview-feedback Archive, May 2007
Diagram Scene example chrashes.
Message 1 in thread
Hi,
Diagram Scene example
http://doc.trolltech.com/4.3/graphicsview-diagramscene.html
This example crashed on adding empty text to the scene.
At diagramscene.cpp:
void DiagramScene::editorLostFocus(DiagramTextItem *item)
{
QTextCursor cursor = item->textCursor();
cursor.clearSelection();
item->setTextCursor(cursor);
if (item->toPlainText().isEmpty()) {
removeItem(item);
delete item;
}
}
DiagramScene::editorLostFocus is called by lostFocus signal which is
emitted from DiagramTextItem::focusOutEvent, and crashes in
QGraphicsTextItem::focusOutEvent.
At diagramtextitem.cpp:
void DiagramTextItem::focusOutEvent(QFocusEvent *event)
{
setTextInteractionFlags(Qt::NoTextInteraction);
emit lostFocus(this);
QGraphicsTextItem::focusOutEvent(event);
}
Although the DiagramTextItem object is already deleted, the object's
data is accessed in QGraphicsTextItem::focusOutEvent.
When I modified like below,
void DiagramScene::editorLostFocus(DiagramTextItem *item)
{
QTextCursor cursor = item->textCursor();
cursor.clearSelection();
item->setTextCursor(cursor);
if (item->toPlainText().isEmpty()) {
removeItem(item);
item->deleteLater(); // instead of `delete item;`
}
}
it did not crash.
--
[ signature omitted ]