PDA

View Full Version : Mapping of .ui elements to object methods



KieranS
31st October 2009, 11:30
When generating cpp code from .ui files, uic has to map elements/properties of the widgets to methods on the object.

For example if I have a widget declaration



<widget class="QPushButton" name="button">
<property name="geometry">
<rect>
<x>910</x>
<y>140</y>
<width>101</width>
<height>117</height>
</rect>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>

I get some cpp code like:


button = new QPushButton(MainUI);
button->setObjectName(QString::fromUtf8("button"));
button->setGeometry(QRect(910, 140, 101, 117));
button->setFlat(true);

I'm wondering how uic knows which elements/properties of the .ui file are mapped to the methods on the objects? I had a quick look at the uic source and the logic seemed to be hard coded in the source rather than a declarative config of rules that could be changed when uic undergoes an upgrade or the Qt API changes.

Does anybody know of a list that specifies how uic maps .UI XML to cpp code?

Regards

axeljaeger
5th November 2009, 06:57
It should use QMetaObject to find the setters for properties. Nokia Qt Development Frameworks might have some shortcuts because dynamically setting properties using QMetaObject is more expensive than calling the setter directly.

If you just want to make your own properties setable, declare them as Q_PROPERTY and you are fine. Don't care about auto-generated code.

wysota
5th November 2009, 21:33
Some things are hardcoded, others are not. You can declare some things when implementing Designer plugins.