Unable to make getOwnPropertyDescriptor working
-
Hi all,
I'm in trouble with Qt 5.7.0 and QML. I need to discover properties of some objects at runtime. No need to expand on the final goal the problem is elsewhere.
I plan to use Object.getOwnPropertyDescriptor but I can't make it works as I want, after hours of test...
Here is a POC in pure QML/JS
import QtQuick 2.0 Item { id: myTest property int myProp : 1234 function test() { console.log("_________________TEST_________________"); console.log(Object.getOwnPropertyNames(myTest)) console.log(myTest.hasOwnProperty("myProp")) console.log(Object.getOwnPropertyDescriptor(myTest, "myProp")); console.log("_________________TEST_________________"); } }
In the log I get:
qml: _________________TEST_________________ qml: [objectName,parent,data,resources,children,x,y,z,width,height,opacity,enabled,visible,visibleChildren,states,transitions,state,childrenRect,anchors,left,right,horizontalCenter,top,bottom,verticalCenter,baseline,baselineOffset,clip,focus,activeFocus,activeFocusOnTab,rotation,scale,transformOrigin,transformOriginPoint,transform,smooth,antialiasing,implicitWidth,implicitHeight,layer,myProp,objectNameChanged,childrenRectChanged,baselineOffsetChanged,stateChanged,focusChanged,activeFocusChanged,activeFocusOnTabChanged,parentChanged,transformOriginChanged,smoothChanged,antialiasingChanged,clipChanged,windowChanged,childrenChanged,opacityChanged,enabledChanged,visibleChanged,visibleChildrenChanged,rotationChanged,scaleChanged,xChanged,yChanged,widthChanged,heightChanged,zChanged,implicitWidthChanged,implicitHeightChanged,update,grabToImage,grabToImage,contains,mapToGlobal,mapFromGlobal,mapFromItem,mapToItem,forceActiveFocus,forceActiveFocus,nextItemInFocusChain,nextItemInFocusChain,childAt,myPropChanged,test] qml: true qml: undefined qml: _________________TEST_________________
According to the line "qml: true" the "hasOwnProperty('myProp')" find the property and say "true".
But the next line trying to get the property descriptor return "undefined".
The one who can solve my problem will be my Hero !
-
Hi and welcome to devnet,
I don't know all the internals of QML but the "property" here matches Qt's property system which is not the same thing as JavaScript properties.
I'd recommend bringing this question on the interest mailing list. You'll find there Qt's developers/maintainers. This forum is more user oriented.