diff options
author | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2010-02-09 08:56:25 (GMT) |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2010-02-10 08:57:17 (GMT) |
commit | b7af368e86874d71ffc9071c9ef009814d6a3467 (patch) | |
tree | 34bc36dbbde9fcdb20ab04a7b68b77c9f7077223 /src/gui/dialogs | |
parent | 6f155d010b6dd5ae3c04e62b3a29f8c0ed9f0a36 (diff) | |
download | Qt-b7af368e86874d71ffc9071c9ef009814d6a3467.zip Qt-b7af368e86874d71ffc9071c9ef009814d6a3467.tar.gz Qt-b7af368e86874d71ffc9071c9ef009814d6a3467.tar.bz2 |
Crash when deleting the parent of a context menu while it is being displayed
Asynchronous deletion of a widget (e.g. calling deleteLater() after a timeout)
could be caught by the context menu's event loop if called with exec() instead
of popup(). This causes the context menu to be deleted twice in some cases,
and a crash generally follows.
Although this introduces a minor behaviour change, we now use popup() with the
WA_DeleteOnClose attribute to display the context menu in all the
contextMenuEvent() bodies, except in those where the menu was already
protected by a QPointer. In QDialog::contextMenuEvent(), we use QWeakPointer
to reflect the fact that the menu was previously allocated in the stack.
QAbstractSpinBox, QDialog and QMdiSubWindow keep using QMenu::exec() in
contextMenuEvent() as they need the QAction returned.
Some auto-tests included.
Reviewed-by: Olivier
Task-number: QTBUG-7902
Diffstat (limited to 'src/gui/dialogs')
-rw-r--r-- | src/gui/dialogs/qdialog.cpp | 7 | ||||
-rw-r--r-- | src/gui/dialogs/qmessagebox.cpp | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/gui/dialogs/qdialog.cpp b/src/gui/dialogs/qdialog.cpp index 9ff2ad8..fb0dba4 100644 --- a/src/gui/dialogs/qdialog.cpp +++ b/src/gui/dialogs/qdialog.cpp @@ -648,13 +648,14 @@ void QDialog::contextMenuEvent(QContextMenuEvent *e) while (w && w->whatsThis().size() == 0 && !w->testAttribute(Qt::WA_CustomWhatsThis)) w = w->isWindow() ? 0 : w->parentWidget(); if (w) { - QMenu p(this); - QAction *wt = p.addAction(tr("What's This?")); - if (p.exec(e->globalPos()) == wt) { + QWeakPointer<QMenu> p = new QMenu(this); + QAction *wt = p.data()->addAction(tr("What's This?")); + if (p.data()->exec(e->globalPos()) == wt) { QHelpEvent e(QEvent::WhatsThis, w->rect().center(), w->mapToGlobal(w->rect().center())); QApplication::sendEvent(w, &e); } + delete p.data(); } #endif } diff --git a/src/gui/dialogs/qmessagebox.cpp b/src/gui/dialogs/qmessagebox.cpp index d1b2e3f..ed437ff 100644 --- a/src/gui/dialogs/qmessagebox.cpp +++ b/src/gui/dialogs/qmessagebox.cpp @@ -92,8 +92,8 @@ public: { #ifndef QT_NO_CONTEXTMENU QMenu *menu = createStandardContextMenu(); - menu->exec(e->globalPos()); - delete menu; + menu->setAttribute(Qt::WA_DeleteOnClose); + menu->popup(e->globalPos()); #else Q_UNUSED(e); #endif |