Good afternoon,
I am developing an application using QML (Qt 5.8) where a TabView is used to control the different forms used. To reduce the number of Tab elements, I am using State in some tabs to control minor differences in the visible Tab content (depending on a test result for instance). I do assign a default state in each Tab, with state transitions are based on a Timer (declared in the Tab) or external test result. This approach works well for cases where a Timer (or external test) is started after a Tab is made current, and using onStateChanged().
Note that the TabView.tabsVisible is set to false.
There is however a case that is failing. The external test is executed in the background while Tab A is current. Depending on the test result Tab B becomes current (test passed), otherwise Tab C is selected to be current, with additional items specific to the test failure. The display the additional items is based on State (specific to Tab C). I have included a partial definition of Tab C
Code:
Item { id: sensorIntegrityTest onEnabledChanged: { console.log( "sensorIntegrityTest.Item.onEnabledChanged, visible: ", visible, ", enabled: ", enabled) } onVisibleChanged: { console.log( "sensorIntegrityTest.Item.onVisibleChanged, visible: ", visible, ", enabled: ", enabled) } property int imageShown : 0 states: [ State { name: "integrity setup" PropertyChanges { target: sensorIntegrityTestFail; visible: false } PropertyChanges { target: sensorIntegrityTestPass; visible: false } }, State { name: "integrity test" PropertyChanges { target: sensorIntegrityTestFail; visible: false } PropertyChanges { target: sensorIntegrityTestPass; visible: false } }, State { name: "integrity failed" PropertyChanges { target: sensorIntegrityTestPass; visible: false } PropertyChanges { target: sensorIntegrityTestFail; visible: true } }, State { name: "integrity passed" PropertyChanges { target: sensorIntegrityTestFail; visible: false } PropertyChanges { target: sensorIntegrityTestPass; visible: true } } ] onStateChanged: { console.log( "sensorIntegrityTest.onStateChanged: state= ", state) if ("integrity test" === state) { integrityTestTimer.start() } else { integrityTestTimer.stop() } } // Assign the default state state: "integrity setup"
I am using a JavaScript function to select the current Tab. When Tab C is selected the following content appears in the console log:
When trying the read the state property value from the Javascript function using the commandCode:
qml: sensorIntegrityTest.onStateChanged: state= integrity setup
the following error is reported: qrc:/screen.js:208: TypeError: Cannot read property 'state' of undefinedCode:
console.log( "state ", tabView.getTab( nextIndex).sensorIntegrityTest.state)
What am I missing? Is it possible to access the state property as currently declared here from a Javascript function?
My last attempt to address this issue, I defined an alias for the state variable in Tab C definition of using the statement
resulting in the following error reported by the Javascript functions: qrc:/screen.js:211: Error: Cannot assign to non-existent property "integrityState"Code:
property alias integrityState: sensorIntegrityTest.state
Regards,
Daniel