1

I am working on making my own designer widget that looks and functions like qt. But now I needed to know how the property is created. I knew we can get the properties of an widget using QMetaObject and QMetaProperty but my question is will I be able to get the class name of each property. Like object name property comes from QObject and geomentry property comes from QWidget. Is it so that i should hard code myself to model or is there a way to get the classInfo from property. I have attached the image which im trying to achieve any response or related post is appreciated.

thanks, enter image description here

vahancho
  • 20,808
  • 3
  • 47
  • 55
anbu selvan
  • 725
  • 3
  • 13
  • 41

1 Answers1

2

In order to create mapping between classes and their properties you need to traverse through your object's class hierarchy. Here is the sample code that crates such mapping:

// Create properties per class mapping for the initialObject.
const QMetaObject *mo = initialObject->metaObject();
QMap<QString, QStringList> propertyMap;
do {
    QStringList properties;
    for(int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) {
        properties << QString::fromLatin1(mo->property(i).name());
    }
    propertyMap[mo->className()] = properties;

} while (mo = mo->superClass());

Now the propertyMap contains all properties sorted by the class names they belong to.

vahancho
  • 20,808
  • 3
  • 47
  • 55
  • thanks for your reply but here the condition you are checking leads to infinite loop but when i debug im able to gets its hierarchy. – anbu selvan Apr 29 '14 at 10:05
  • @anbuselvan, which condition? `QMetaObject::superClass()` returns the meta-object of the superclass, or 0 if there is no such object. – vahancho Apr 29 '14 at 10:11
  • the while condition remains always true for me when i run your code for customclasswidget .I think im missing some thing.... – anbu selvan Apr 29 '14 at 10:13