diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-11-16 15:29:34 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2009-11-18 03:53:07 (GMT) |
commit | 7ca2dacff951827daa7bc4d7da1832b282c19a8f (patch) | |
tree | 386233a382b8df8931ee67cae93940c6709e9cd0 | |
parent | 964474223ea45587059802dcd52cde9fdaeb4bee (diff) | |
download | Qt-7ca2dacff951827daa7bc4d7da1832b282c19a8f.zip Qt-7ca2dacff951827daa7bc4d7da1832b282c19a8f.tar.gz Qt-7ca2dacff951827daa7bc4d7da1832b282c19a8f.tar.bz2 |
QMenu: do not crash if action is destroyed in the triggered signal.
Task-number: QTBUG-4480
Reviewed-by: Thierry
(cherry picked from commit dc2cb80ceb35edd958685189e9075ac1061870f4)
-rw-r--r-- | src/gui/widgets/qmenu.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qmenu/tst_qmenu.cpp | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index cc39b7f..9603559 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -1107,6 +1107,7 @@ void QMenuPrivate::_q_actionTriggered() { Q_Q(QMenu); if (QAction *action = qobject_cast<QAction *>(q->sender())) { + QWeakPointer<QAction> actionGuard = action; #ifdef QT3_SUPPORT //we store it here because the action might be deleted/changed by connected slots const int id = q->findIdForAction(action); @@ -1116,7 +1117,7 @@ void QMenuPrivate::_q_actionTriggered() emit q->activated(id); #endif - if (!activationRecursionGuard) { + if (!activationRecursionGuard && actionGuard) { //in case the action has not been activated by the mouse //we check the parent hierarchy QList< QPointer<QWidget> > list; diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index f12fa92..f0f69a4 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -101,11 +101,13 @@ private slots: void menuSizeHint(); void task258920_mouseBorder(); void setFixedWidth(); + void deleteActionInTriggered(); protected slots: void onActivated(QAction*); void onHighlighted(QAction*); void onStatusMessageChanged(const QString &); void onStatusTipTimer(); + void deleteAction(QAction *a) { delete a; } private: void createActions(); QMenu *menus[2], *lastMenu; @@ -858,6 +860,17 @@ void tst_QMenu::setFixedWidth() QCOMPARE(menu.sizeHint().width(), menu.minimumWidth()); } +void tst_QMenu::deleteActionInTriggered() +{ + // should not crash + QMenu m; + QObject::connect(&m, SIGNAL(triggered(QAction*)), this, SLOT(deleteAction(QAction*))); + QWeakPointer<QAction> a = m.addAction("action"); + a.data()->trigger(); + QVERIFY(!a); +} + + QTEST_MAIN(tst_QMenu) |