Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105821

Qt.labs.platform "Preferences" MenuItem crashes app on macOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P1: Critical
    • None
    • 6.3.1
    • GUI: Menus, Quick: Other
    • None
    • macOS 12.15.1 on Apple Silicon M1 processor. QT 6.3.1, QT Creator 8.0.1; building with qmake.
    • macOS

    Description

      Using Qt.labs.platform's native MenuBar, Menu, and MenuItems. Having a "Preferences" MenuItem as the sole item in an "Edit" menu, either by name or by role, causes the resulting app to crash on macOS on Apple Silicon. Specifically, in the QML file:

      import Qt.labs.platform as Labs
      ...
      
          property Labs.MenuBar nativeMenu: Labs.MenuBar  {
              id: nativeMenuBar
              ...
              Labs.Menu {
                  id: editMenu
                  title: qsTr("&Edit")                     // [1]
                  Labs.MenuItem {
                      text: qsTr("Pr&eferences...")        // [2]
                      role: Labs.MenuItem.PreferencesRole  // [3]
                      onTriggered: prefsDialog.open()
                  }
              }
           ...
           }

      [1]'s title must be "Edit" or "&Edit". Then, if [2]'s text is "Preferences", or if [3] is present regardless of [2]'s text, running the app crashes with:

      2022-08-18 18:12:09.888 QtTest[14259:200956] *** Assertion failure in -[QCocoaNSMenu itemAtIndex:], NSMenu.m:1024
      2022-08-18 18:12:09.888 QtTest[14259:200956] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: index >= 0'
      *** First throw call stack:
      (
       0   CoreFoundation                      0x000000019a8851a8 __exceptionPreprocess + 240 0   CoreFoundation                      0x000000019a8851a8 __exceptionPreprocess + 240
       1   libobjc.A.dylib                     0x000000019a5cfe04 objc_exception_throw + 60 1   libobjc.A.dylib                     0x000000019a5cfe04 objc_exception_throw + 60
       2   Foundation                          0x000000019b7bce88 -[NSCalendarDate initWithCoder:] + 0 2   Foundation                          0x000000019b7bce88 -[NSCalendarDate initWithCoder:] + 0
       3   AppKit                              0x000000019d35a65c -[NSMenu itemAtIndex:] + 188 3   AppKit                              0x000000019d35a65c -[NSMenu itemAtIndex:] + 188
       4   libqcocoa.dylib                     0x000000010410e6b0 qt_plugin_instance + 126724 4   libqcocoa.dylib                     0x000000010410e6b0 qt_plugin_instance + 126724
       5   libqcocoa.dylib                     0x000000010410e254 qt_plugin_instance + 125608 5   libqcocoa.dylib                     0x000000010410e254 qt_plugin_instance + 125608
       6   libqtlabsplatformplugin.dylib       0x000000010ab7d524 libqtlabsplatformplugin.dylib + 87332 6   libqtlabsplatformplugin.dylib       0x000000010ab7d524 libqtlabsplatformplugin.dylib + 87332
       7   QtQml                               0x00000001044ff924 _ZN17QQmlObjectCreator8finalizeER26QQmlInstantiationInterrupt + 1280 7   QtQml                               0x00000001044ff924 _ZN17QQmlObjectCreator8finalizeER26QQmlInstantiationInterrupt + 1280
       8   QtQml                               0x000000010449ea8c _ZN20QQmlComponentPrivate8completeEP17QQmlEnginePrivatePNS_17ConstructionStateE + 64 8   QtQml                               0x000000010449ea8c _ZN20QQmlComponentPrivate8completeEP17QQmlEnginePrivatePNS_17ConstructionStateE + 64
       9   QtQml                               0x000000010449c488 _ZN20QQmlComponentPrivate14completeCreateEv + 432 9   QtQml                               0x000000010449c488 _ZN20QQmlComponentPrivate14completeCreateEv + 432
       10  QtQml                               0x000000010449dbfc _ZN13QQmlComponent6createEP11QQmlContext + 84 10  QtQml                               0x000000010449dbfc _ZN13QQmlComponent6createEP11QQmlContext + 84
       11  QtQml                               0x0000000104484aa8 _ZN28QQmlApplicationEnginePrivate10finishLoadEP13QQmlComponent + 152 11  QtQml                               0x0000000104484aa8 _ZN28QQmlApplicationEnginePrivate10finishLoadEP13QQmlComponent + 152
       12  QtQml                               0x00000001044849f4 _ZN28QQmlApplicationEnginePrivate9startLoadERK4QUrlRK10QByteArrayb + 828 12  QtQml                               0x00000001044849f4 _ZN28QQmlApplicationEnginePrivate9startLoadERK4QUrlRK10QByteArrayb + 828
       13  QtQml                               0x0000000104484fe4 _ZN21QQmlApplicationEngine4loadERK4QUrl + 36 13  QtQml                               0x0000000104484fe4 _ZN21QQmlApplicationEngine4loadERK4QUrl + 36
       14  QtTest                              0x00000001029160d4 main + 284 14  QtTest                              0x00000001029160d4 main + 284
       15  dyld                                0x000000010293508c start + 520 15  dyld                                0x000000010293508c start + 520
      )
      libc++abi: terminating with uncaught exception of type NSException
      18:12:09: /Volumes/2TB/scratch/build-QtTest-Qt_6_3_1_for_macOS-Debug/QtTest.app/Contents/MacOS/QtTest crashed.
      
      

      The same code builds and runs on Windows without a problem.

      An "About" MenuItem does not cause the same problem, even if it's the only item in its menu. On macOS it gets properly relocated into the App Menu as "About <appName>" and functions as expected.

      Adding one or more additional items to the Edit menu, before or after "Preferences", prevents the crash. Renaming the "Edit" menu to something else ("Frog") also prevents the crash. In these cases Preferences gets relocated to the App menu, as it should.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              tpochep Timur Pocheptsov
              adam_wilt Adam Wilt
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes