Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
5.3.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:
singleton MySingleton 1.0 MySingleton.qml
pragma Singleton import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 Item { property Component buttonStyle: ButtonStyle { } }
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:
********* 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:
...
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:
/*! \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:
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
- duplicates
-
QTBUG-38422 TypeError on destruction of Button with style bound to Singleton property
- Closed
- is duplicated by
-
QTBUG-48016 "TypeError: Cannot read property of null" warning when closing application with a ButtonStyle component defined in a QML singleton
- Closed