Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Unable to make getOwnPropertyDescriptor working
Qt 6.11 is out! See what's new in the release blog

Unable to make getOwnPropertyDescriptor working

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 684 Views 2 Watching
  • 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 Offline
    W Offline
    WalterKoenig
    wrote on last edited by A Former User
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved