summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYulong Bai <yulong.bai@qt.io>2017-12-18 12:55:15 +0100
committerYulong Bai <yulong.bai@qt.io>2018-01-21 17:54:47 +0000
commit4d898a73e63e69e63bcb2c26ca15da595d7efb7a (patch)
tree62bddc4e70aad7f542fb8340dd2ccd34dc8b440a /tests
parentb3e7e9b182cb5a5e2b5e3592352ff1ea0e264c2d (diff)
QMenuBar: Fix repetitive emission of triggered() when using addAction(QString)
The action which added by QMenuBar::addAction(const QString &text) already connected relevant signals and slots implicitly, however, while QMenuBarPrivate::updateGeometry -ing, it reconnects them if there's a extension button associated with a hidden popup menu. In that case the QMenuBar::triggered would be fired twice. Since the QAction's ownership may be changed or added dynamically, there are still very rare cases like several widgets share the same QAction object to result in this problem. [ChangeLog][QtWidgets][QMenu] Fixed a bug in QMenu that caused QMenuBar::triggered to be fired multiple times. Task-number: QTBUG-25669 Change-Id: I4d52e82a2136a992e0b37118e41237d96a2c5d22 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
index 26ef228130..52726c64ac 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
@@ -148,11 +148,10 @@ private slots:
void taskQTBUG56275_reinsertMenuInParentlessQMenuBar();
void QTBUG_57404_existingMenuItemException();
#endif
+ void QTBUG_25669_menubarActionDoubleTriggered();
void taskQTBUG55966_subMenuRemoved();
void QTBUG_58344_invalidIcon();
-
void platformMenu();
-
void addActionQt5connect();
protected slots:
@@ -1633,6 +1632,31 @@ void tst_QMenuBar::addActionQt5connect()
QVERIFY(flag);
}
+void tst_QMenuBar::QTBUG_25669_menubarActionDoubleTriggered()
+{
+ QMainWindow win;
+ win.menuBar()->setNativeMenuBar(false);
+ QAction *act1 = win.menuBar()->addAction("Action1");
+ QAction *act2 = win.menuBar()->addAction("Action2");
+ QSignalSpy spy(win.menuBar(), &QMenuBar::triggered);
+
+ win.show();
+ QApplication::setActiveWindow(&win);
+ QVERIFY(QTest::qWaitForWindowExposed(&win));
+
+ QPoint posAct1 = menuBarActionWindowPos(win.menuBar(), act1);
+ QPoint posAct2 = menuBarActionWindowPos(win.menuBar(), act2);
+
+ QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct1);
+ QTRY_COMPARE(spy.count(), 1);
+
+ QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct2);
+ QTRY_COMPARE(spy.count(), 2);
+
+ QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct2);
+ QTRY_COMPARE(spy.count(), 3);
+}
+
void tst_QMenuBar::slotForTaskQTBUG53205()
{
QWidget *parent = taskQTBUG53205MenuBar->parentWidget();