How to do a “is_a”, “typeof” or instanceof in QML?

后端 未结 4 1891
南旧
南旧 2020-12-23 21:00

I want to run through a list of QML components and choose one type:

for (var i = 0; i < controls.children.length; ++i) {
     if ( typeof (controls.childr         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-23 21:52

    Yes, this thread is 2 yrs old but perhaps my answer could help someone out there.

    For me, it was good enough use JSON.stringify() to compare QML elements. Of course, if two different elements have exactly the same properties and values, this would give you false positive. (eg when one element is on top of another with same color, x, y, etc)

    toString() did not work for me since I've created many instances from same base component. Setting objectName to every instance would have been a bit too much for my use case.

提交回复
热议问题