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

Action items may be erroneously garbage-collected when created inline

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.3.0 Beta1, 5.3.0 RC1
    • 5.2.0
    • Quick: Controls 1
    • None
    • Ubuntu 13.04 x64, stock gcc
    • qtquickcontrols:37b8de375bf6145bced8264b280dfd10e114ff3a

    Description

      Look at the following example (also linked to the report), if you click the item and trigger the action, the latter obviously gets destructed, and crashes the application:

      import QtQuick 2.1
      import QtQuick.Controls 1.1
      
      Item {
          width: 400; height: 200
      
          Action {
              id: action2
              text: "Action2"
          }
      
          Menu {
              id: menu
              MenuItem {
                  id: menuItem
                  action: Action {
                      id: action1
                      text: "Action1"
                      onTriggered: {
                          menuItem.action = action2
                      }
                  }
              }
          }
      
          //how this should have prevented GC-ing
          property QtObject action1Ref: action1
      
          MouseArea {
              anchors.fill: parent
              onClicked: menu.popup()
          }
      }
      

      The console output is:

      Object 0xf98140 destroyed while one of its QML signal handlers is in progress.
      Most likely the object was deleted synchronously (use QObject::deleteLater() instead), or the application is running a nested event loop.
      This behavior is NOT supported!
      <Unknown File>:65535: function()

      Unknown macro: { [code] }

      The program has unexpectedly finished.

      Note that there's a reference to the action in the scene, which should have prevented destruction in the first place, but even despite that, garbage-collected actions should probably account for coming out of scope in an onTriggered handler, and use deleteLater (just like the console warning says).

      Attachments

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

        Activity

          People

            dedietri Gabriel de Dietrich (drgvond)
            mlvljr Vladimir M.
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes