[SOLVED (work-around)] QML Calling overriden functions
-
Hi, I'm playing with inheritance in QML and don't know how to call an overridden function. Below is a simple example that, hopefully, explains what I'm trying to do.
Thanks in advance.
Yours
/peterParent.qml: @
import QtQuick 1.1
Rectangle {
function foo() {
console.log("Foo in parent")
}
}@Child.qml:
@
import QtQuick 1.1Parent {
function foo() {
console.log("Foo in child")
// here is the problem. Would like to do something like: Parent::foo()
}
}@Output:
@
Foo in child
@While I would like it to be:
@
Foo in child
Foo in parent
@ -
No time to check myself at the moment, but have you tried this:
@
import QtQuick 1.1Parent {
id: rootfunction foo() { root.foo(); console.log("Foo in child") }
}
@Probably won't work, or will introduce some nasty loop, but worth a try nonetheless.
-
Thanks for you answer, but unfortunately it does go into a nasty loop :-(
-
A kind of a workaround, if you are interested in those, would be this:
@
// Parent
import QtQuick 1.1Rectangle {
signal foo(); onFoo: { console.log("Foo in parent"); }
}
// Kid
import QtQuick 1.1Parent {
id: rootonFoo: { console.log("Foo in child"); }
}
@This time I've checked - it works :)
-
Although in a reversed order to the one you were interested in. Parent reports first.
-
https://bugreports.qt-project.org/browse/QTBUG-25942 and https://bugreports.qt-project.org/browse/QTBUG-26357 are related to this issue. Both of these are in scope for Qt 5.1.
Cheers,
Chris. -
Good to know, thanks!
-
Thanks for all your answers. Very helpful :-)