Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Unable to make getOwnPropertyDescriptor working

    QML and Qt Quick
    2
    2
    447
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      WalterKoenig last edited by A Former User

      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 !

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • First post
          Last post