Trying to get this to work in Qt version 5.9
It seems that whenever I create an object within a QML Tab it is unrecognizable by the parent object (or any of the parent's parents, and so on). How do I get the parent objects to recognize the object in the Tab? Or, if impossible, then what is a work-around to call the function of the object within the Tab?
I've boiled down the code to this simplified example:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
Window {
Rectangle {
id: myFunctionCaller
Component.onCompleted: {
myParent.myFunction();
myChild.myFunction();
myGrandChild.myFunction();
}
}
TabView {
id: myParent
property Rectangle grandchild: myGrandChild
onGrandchildChanged: console.log("Parent recognizes GrandChild");
function myFunction() {
console.log("I'm the Parent");
}
Tab{
id: myChild
property Rectangle grandchild: myGrandChild
onGrandchildChanged: console.log("Child recognizes GrandChild");
function myFunction() {
console.log("I'm the Child");
}
Rectangle {
id: myGrandChild
function myFunction() {
console.log("I'm the GrandChild");
}
}
}
}
}
I expect this output:
I'm the Parent
I'm the Child
I'm the GrandChild
Parent recognizes Grandchild
Child recognizes Grandchild
However, I get this output:
I'm the Parent
I'm the Child
ReferenceError: myGrandChild is not defined.
ReferenceError: myGrandChild is not defined.
ReferenceError: myGrandChild is not defined.
The error occurs on these lines:
myGrandChild.myFunction();
onGrandchildChanged: console.log("Parent recognizes GrandChild");
onGrandchildChanged: console.log("Child recognizes GrandChild");