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

TypeError on destruction of Button with style bound to Singleton property

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.3.1
    • Quick: Controls 1
    • None

    Description

      We've got a QML singleton that we use to hold global properties relating to various project aspects, like styling. For our Button subclass, we bind its style property to the corresponding property on the Singleton. This way, we can easily make global styling changes on the fly at runtime from within the app. It works like a charm, but we're seeing an error whenever one of these buttons is destroyed.

      I've boiled it down to a minimal reproduction:

      qmldir
      singleton MySingleton 1.0 MySingleton.qml
      
      MySingleton.qml
      pragma Singleton
      
      import QtQuick 2.2
      import QtQuick.Controls 1.2
      import QtQuick.Controls.Styles 1.2
      
      Item {
        property Component buttonStyle: ButtonStyle { }
      }
      
      tst_test.qml
      import QtTest 1.0
      import QtQuick 2.2
      import QtQuick.Controls 1.2
      
      // For MySingleton
      import "."
      
      Button {
        style: MySingleton.buttonStyle
        
        TestCase {
          name: "test"
          when: windowShown
          
          function test_nothing() { wait(100) }
        }
      }
      

      And the output looks like this:

      output of qmltestrunner
      ********* Start testing of qmltestrunner *********
      Config: Using QtTest library 5.3.1, Qt 5.3.1
      PASS   : qmltestrunner::test::initTestCase()
      PASS   : qmltestrunner::test::test_nothing()
      PASS   : qmltestrunner::test::cleanupTestCase()
      Totals: 3 passed, 0 failed, 0 skipped
      ********* Finished testing of qmltestrunner *********
      file:///home/jemc/Qt/5.3/gcc_64/qml/QtQuick/Controls/Styles/Base/ButtonStyle.qml:160: TypeError: Cannot read property of null
      

      The code at line 160 of QtQuick/Controls/Styles/Base/ButtonStyle.qml looks like this:

      ButtonStyle.qml
      ...
      158:    /*! \internal */
      159:    property Component panel: Item {
      160:        anchors.fill: parent
      ...
      

      If I change add some debugging statements to the binding, to look like this:

      ButtonStyle.qml (altered)
          /*! \internal */
          property Component panel: Item {
              anchors.fill: {
                  console.log("about to print parent of",this)
                  console.log("parent:",parent)
                  console.log("just printed parent of",this)
                  return parent
              }
      

      Then I get this as the output:

      output of qmltestrunner with ButtonStyle.qml altered
      qml: about to print parent of QQuickItem(0x25eedf0)
      qml: parent: QQuickLoader(0x24676e0)
      qml: just printed parent of QQuickItem(0x25eedf0)
      ********* Start testing of qmltestrunner *********
      Config: Using QtTest library 5.3.1, Qt 5.3.1
      PASS   : qmltestrunner::test::initTestCase()
      PASS   : qmltestrunner::test::test_nothing()
      PASS   : qmltestrunner::test::cleanupTestCase()
      Totals: 3 passed, 0 failed, 0 skipped
      ********* Finished testing of qmltestrunner *********
      qml: about to print parent of [object Object]
      file:///home/jemc/Qt/5.3/gcc_64/qml/QtQuick/Controls/Styles/Base/ButtonStyle.qml:162: TypeError: Cannot read property of null
      

      This is interesting, because in the second case (right before the error) it looks like the value of "this" is not the QQuickItem it should be, but some other JS object. And when it tries to even access the "parent" object to print it, it triggers the TypeError and bails out of the function.

      Attachments

        Issue Links

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

          Activity

            People

              bachewii Jens
              jemc Joe Eli McIlvain
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes