Make QToolButtonPrivate::popupTimerDone() more robust

Avoid dereferencing the q-pointer if the button has been
destructed meanwhile popup was open.

Task-number: QTBUG-26956
Change-Id: I68190e9fe84c669229ae0ce4d573ee7a02a8a141
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
J-P Nurmi 2014-02-05 11:48:51 +01:00 committed by The Qt Project
parent be51772d02
commit 4d6cb199b8
2 changed files with 14 additions and 3 deletions

View File

@ -778,15 +778,16 @@ void QToolButtonPrivate::popupTimerDone()
actualMenu->d_func()->causedPopup.action = defaultAction;
actionsCopy = q->actions(); //(the list of action may be modified in slots)
actualMenu->exec(p);
if (!that)
return;
QObject::disconnect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
if (mustDeleteActualMenu)
delete actualMenu;
else
QObject::disconnect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
if (!that)
return;
actionsCopy.clear();
if (repeat)

View File

@ -63,6 +63,7 @@ private slots:
void collapseTextOnPriority();
void task230994_iconSize();
void task176137_autoRepeatOfAction();
void qtbug_26956_popupTimerDone();
protected slots:
void sendMouseClick();
@ -223,5 +224,14 @@ void tst_QToolButton::sendMouseClick()
QTest::mouseClick(w, Qt::LeftButton, 0, QPoint(7,7));
}
void tst_QToolButton::qtbug_26956_popupTimerDone()
{
QToolButton *tb = new QToolButton;
tb->setMenu(new QMenu(tb));
tb->menu()->addAction("Qt");
tb->deleteLater();
tb->showMenu();
}
QTEST_MAIN(tst_QToolButton)
#include "tst_qtoolbutton.moc"