Not able to inline JS function when overriding
Solved
QML and Qt Quick
-
I have a generic component that defines a generic function for MouseArea.onPressed events. When I create an instance of this component I want to override this function. It works if I define the function first and then override the generic function but it doesn't work if I try to do this inline.
Example:
My generic componentimport QtQuick 2.0 Rectangle { property int posX property int posY property string imageSource property string entryText function onPress() { console.log("NavigationBarEntry Pressed: " + entryText) } property var entryOnPressed: (onPress) width: parent.width height: 56 color: mBrandingDefsId.cThemeL1Bars x: posX y: posY Image { source: imageSource width: 35 height: 35 x: 8 anchors.verticalCenter: parent.verticalCenter } Text { text: entryText x: 62 font { family: boldFont.name pixelSize: 20 bold: true } anchors.verticalCenter: parent.verticalCenter } MouseArea { anchors.fill: parent onPressed: onPress() } }
When creating an instance of this, the following will work:
NavigationBarEntry { entryText: "Home" function onPress() { console.log("Pressed Home") } entryOnPressed: (onPress) }
But this will not:
NavigationBarEntry { entryText: "Home" entryOnPressed: (function() { console.log("Pressed Home") }) }
It seems this should be possible. What I'm I missing?
Thanks.