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. Get values from nested properties

Get values from nested properties

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • T Offline
    T Offline
    ttuna
    wrote on last edited by
    #1

    I'm trying to read values from nested properties:

    // root class ...
    class TestRootClass : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
        Q_PROPERTY(TestPropertyObject test READ test WRITE setTest NOTIFY testChanged)
    ...
    }
    
    // class of property in root class
    class TestPropertyObject
    {
        Q_GADGET
        Q_PROPERTY(QString name READ name WRITE setName)
        Q_PROPERTY(int count READ count WRITE setCount)
    ...
    }
    

    I want to read Q_PROPERTY values from any arbitrary object but taking into account the property-hierarchy as far as possible and got this far:

    QMap(
    	("applicationName", QVariant(QString, "applicationName"))
    	("applicationVersion", QVariant(QString, "applicationVersion"))
    	("objectName", QVariant(QString, "objectName"))
    	("organizationDomain", QVariant(QString, "organizationDomain"))
    	("organizationName", QVariant(QString, "organizationName"))
    	("quitLockEnabled", QVariant(QString, "quitLockEnabled"))
    	("name", QVariant(QString, "name"))
    	("test", QVariant(QVariantMap, QMap(
    		("count", QVariant(QString, "count"))
    		("name", QVariant(QString, "name"))
    	)))
    )
    

    The problem is that this QMap is based on staticMetaObject informations and therefor there are no values available.

    Any idea how i can retrieve the values of these nested properties?

    BR

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi! I'm not sure what you want to achieve. You can retrieve every QObject's attached QMetaObject with

      QObject *obj = new TestRootClass;
      QMetaObject *mo = obj->metaObject(); 
      

      You can now access all its properties (with property(index)) and then read the value of this property from your actual object (.read(obj)).

      
      for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) {
          QVariant tmp = mo->property(i).read(obj);
          qDebug() << tmp;
      }
      

      Hope it helps!

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

        Thanks for your reply.
        The problem is that i can't get a proper object from a property (- just QVariant or void*).
        So how can i access the MetaObject of this property object?

        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