Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The Order of Q_PROPERTies in QMetaObject
Forum Updated to NodeBB v4.3 + New Features

The Order of Q_PROPERTies in QMetaObject

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 351 Views 1 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.
  • T Offline
    T Offline
    Tomi
    wrote on last edited by Tomi
    #1

    Hi,

    I have a class ( for example XYZ ), which has many properties, like this:

    (...)
        Q_OBJECT
        Q_PROPERTY(SomeClass1* SC1 READ getSC1 WRITE setSC1 )
        Q_PROPERTY(SomeClass2* SC2 READ getSC2 WRITE setSC2 )
        Q_PROPERTY(SomeClass3* SC3 READ getSC3 WRITE setSC3 )
        Q_PROPERTY(SomeClass4* SC4 READ getSC4 WRITE setSC4 )
        Q_PROPERTY(SomeClass5* SC5 READ getSC5 WRITE setSC5 )
    (...)
    

    Now I would like to iterate over that properties, like this:

        auto metaObjectXYZ = objectXYZ->metaObject();
    
        for(int i=metaObjectXYZ->propertyOffset(); i<metaObjectXYZ->propertyCount(); i++) {
            auto nextValue = metaObjectXYZ->property(i).read(objectXYZ);
        }
    

    The order of properties in this iteration, will always be the same as in the XYZ class header, so I get: sc1Obj, sc2Obj, sc3Obj, sc4Obj, sc5Obj? Or can I get a different order like sc4Obj, sc1Obj, sc5Obj, sc3Obj, sc2Obj ?

    A 1 Reply Last reply
    0
    • T Tomi

      Hi,

      I have a class ( for example XYZ ), which has many properties, like this:

      (...)
          Q_OBJECT
          Q_PROPERTY(SomeClass1* SC1 READ getSC1 WRITE setSC1 )
          Q_PROPERTY(SomeClass2* SC2 READ getSC2 WRITE setSC2 )
          Q_PROPERTY(SomeClass3* SC3 READ getSC3 WRITE setSC3 )
          Q_PROPERTY(SomeClass4* SC4 READ getSC4 WRITE setSC4 )
          Q_PROPERTY(SomeClass5* SC5 READ getSC5 WRITE setSC5 )
      (...)
      

      Now I would like to iterate over that properties, like this:

          auto metaObjectXYZ = objectXYZ->metaObject();
      
          for(int i=metaObjectXYZ->propertyOffset(); i<metaObjectXYZ->propertyCount(); i++) {
              auto nextValue = metaObjectXYZ->property(i).read(objectXYZ);
          }
      

      The order of properties in this iteration, will always be the same as in the XYZ class header, so I get: sc1Obj, sc2Obj, sc3Obj, sc4Obj, sc5Obj? Or can I get a different order like sc4Obj, sc1Obj, sc5Obj, sc3Obj, sc2Obj ?

      A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      @Tomi
      It's a reasonable assumption that they will be in order, but I would not depend on it.

      What logic do you want to build on that?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tomi
        wrote on last edited by
        #3

        @Asperamanca
        I get data from device

        A 1 Reply Last reply
        0
        • T Tomi

          @Asperamanca
          I get data from device

          A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          @Tomi
          You could save property name / property value pairs

          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