STILL UNSOLVED While the fix of my bug works for the Text item it does NOT work for the MouseArea. console.log(key.keyMouseArea)
results in 'undefined'. But I can access it using key.children[1]
!?!?!
PARTLY SOLVED: My fault, as text
was a property of a child and I can access it using key.textField.text
.
I pass an QtQuick object to a javascript function of another QtQuick object using the this
pointer. In the called function I can see, in the log output, that the passing succeeded (VirtualKey_QMLTYPE_0(0x14a6bf0)). Now, I wish to access the properties of this object but the object is anonymous, or so. How can I convert or cast this parameter into its original type ?
Something like Qt.castToQtQuickObject(pointer, VirtualKey)
or similar.
The available createComponent
or createObject
methods do not what I need as these create new instances.
Some file.qml:
Controller {
id: controller
}
VirtualKey {
Text { // didn't think of this child when asking ...
id: textField
text: "Hallo"
}
MouseArea {
objectName: "mouse"
id: keyMouseArea
}
Component.onCompleted: {
controller.registerKey(this) // passing this instance of VirtualKey
}
}
Controller.qml:
QtObject {
function registerKey(key) {
console.log("VKC: registering key " + key)
// Output: VirtualKey_QMLTYPE_0(0x14a6bf0)
console.log(key.textField) // works
console.log(key.keyMouseArea) // undefined !!!
console.log(key.children[1]) // works
console.log(key.children[1].objectName) // -> "mouse"
}
}
key.text
? If so, what is the output? From what I know QML&Javascript are very flexible on this matter and you should be able to get the value of the property - Amfasisid
for the object and so pass it instead? - folibis