summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-11-16 15:29:34 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-11-16 15:45:28 (GMT)
commitdc2cb80ceb35edd958685189e9075ac1061870f4 (patch)
tree705c27d553caaad06396d2c75cadfcbfcac6ddd6
parent9da9339e4ced8d8c54a4585d3e94cbe6a2d9c574 (diff)
downloadQt-dc2cb80ceb35edd958685189e9075ac1061870f4.zip
Qt-dc2cb80ceb35edd958685189e9075ac1061870f4.tar.gz
Qt-dc2cb80ceb35edd958685189e9075ac1061870f4.tar.bz2
QMenu: do not crash if action is destroyed in the triggered signal.
Task-number: QTBUG-4480 Reviewed-by: Thierry
-rw-r--r--src/gui/widgets/qmenu.cpp3
-rw-r--r--tests/auto/qmenu/tst_qmenu.cpp13
2 files changed, 15 insertions, 1 deletions
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp
index 54d1612..fc88d06 100644
--- a/src/gui/widgets/qmenu.cpp
+++ b/src/gui/widgets/qmenu.cpp
@@ -1106,6 +1106,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);
@@ -1115,7 +1116,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)