Results 1 to 3 of 3

Thread: Mapping of .ui elements to object methods

  1. #1
    Join Date
    Oct 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Mapping of .ui elements to object methods

    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

    Qt Code:
    1. <widget class="QPushButton" name="button">
    2. <property name="geometry">
    3. <rect>
    4. <x>910</x>
    5. <y>140</y>
    6. <width>101</width>
    7. <height>117</height>
    8. </rect>
    9. </property>
    10. <property name="flat">
    11. <bool>true</bool>
    12. </property>
    13. </widget>
    To copy to clipboard, switch view to plain text mode 

    I get some cpp code like:

    Qt Code:
    1. button = new QPushButton(MainUI);
    2. button->setObjectName(QString::fromUtf8("button"));
    3. button->setGeometry(QRect(910, 140, 101, 117));
    4. button->setFlat(true);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Mapping of .ui elements to object methods

    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.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Mapping of .ui elements to object methods

    Some things are hardcoded, others are not. You can declare some things when implementing Designer plugins.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Mapping JS Object properties to QProperties
    By Scorp2us in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2009, 20:52
  2. Replies: 4
    Last Post: 19th February 2009, 11:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.