diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-02-08 16:37:29 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-02-09 18:19:57 +0100 |
commit | 851143eff14dd732fea6be10b96c0bfc798cd629 (patch) | |
tree | 0e17933e536d5c4e6972b47bea5cf96f07843f73 /tests/auto/widgets | |
parent | 15caa47e4ba3822dc329010c3a305bc3f5662cbe (diff) |
macOS: Prevent recursion when modifying the edit menu
Amends d42cfeb84faf154b46f2811b2059946b396fcc12, which would result in
infinite recursion when the Edit menu was populated and added to the
menubar after the menubar has been shown.
Add a macOS-only test case that reproduces the crash without the fix.
Fixes: QTBUG-100441
Pick-to: 6.3
Change-Id: I018a7aa7f01558a3b9732b4d6d96a911dc7fbd19
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 1b8de0b75c..ae08c7ae98 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -40,6 +40,7 @@ #include <QVBoxLayout> #include <QLabel> #include <QPlainTextEdit> +#include <QTranslator> #include <qscreen.h> #include <qobject.h> @@ -144,6 +145,8 @@ private slots: #ifdef Q_OS_MACOS void taskQTBUG56275_reinsertMenuInParentlessQMenuBar(); void QTBUG_57404_existingMenuItemException(); + void defaultEditMenuItems(); + #endif void QTBUG_25669_menubarActionDoubleTriggered(); void taskQTBUG55966_subMenuRemoved(); @@ -1818,6 +1821,32 @@ void tst_QMenuBar::QTBUG_57404_existingMenuItemException() QTest::qWait(100); // No crash, all fine. Ideally, there should be only one warning. } + +void tst_QMenuBar::defaultEditMenuItems() +{ + class TestTranslator : public QTranslator + { + public: + QString translate(const char *context, const char *sourceText, + const char *disambiguation = nullptr, int n = -1) const override + { + if (QByteArrayView(context) == "QCocoaMenu" && QByteArrayView(sourceText) == "Edit") + return QString("Editieren"); + return QTranslator::translate(context, sourceText, disambiguation, n); + } + } testTranslator; + qApp->installTranslator(&testTranslator); + + QMainWindow mw; + mw.show(); + QVERIFY(QTest::qWaitForWindowActive(&mw)); + + mw.menuBar()->addMenu("Editieren")->addAction("Undo"); + + mw.hide(); + mw.show(); + // this should not crash with infinite recursion +} #endif // Q_OS_MACOS void tst_QMenuBar::taskQTBUG55966_subMenuRemoved() |