in Hacking

Crash when deleting QGraphicsProxyWidget

Currently I'm working on a track-based event editor. I'm building this editor with a QGraphicsScene. I use multiple QGraphicsViews for showing tracks and midi-events. Wave files etc...

To rename a track I was trying to show a QLineEdit directly above the track-name and commit the result when editing was completed.

Adding it to the scene like this:

QLineEdit* lineEdit = new QLineEdit("My Text");
// a few connected signals for listening to editingFinished and enterPressed
QGraphicsProxyWidget* proxyWidget = graphicsScene->addWidget( lineEdit )

While I was trying to delete a simple QGraphicsProxyWidget from my QGraphicsScene
it resulted in a crash. (Deleting proxyWidget also delete's it's QLineEdit child)

delete proxyWidget;

The stack-trace shows something about focus function withing Qt.
I tried several things like deleteLater. Calling clearFocus myself.
It all did not work..

The solution that worked for me is the following:

void editingFinishedHandler()
{
  scene()->removeItem( proxyWidget );
  proxyWidget->deleteLater();
}


(My previous solution, that's inferior to the one above: )


void editingFinishedHandler()
{
  proxyWidget->setWidget(0);  // < inferior solution, please see solution above
  proxyWidget->deleteLater();      
  lineEdit->deleteLater();    
}
Share
  • Related Content by Tag