Results 1 to 2 of 2

Thread: Dynamic access of ui items

  1. #1
    Join Date
    Nov 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Dynamic access of ui items

    Hello,

    I'm looking for a way to acces ui items dynamically.

    In detail:

    My program receives a command from about 50 register states. Each register has it's own item on the ui. The item could either be a lineEdit or a checkBox.

    After receiving the status I'm going to look up the registers ui-item in a "database" (up till now most likely a textfile).

    Qt Code:
    1. receivedData = receive();
    2. register = receivedData[0];
    3. item = lookup(register);
    4. if (lineEdit)
    5. {
    6. item->setText(receivedData[1]);
    7. }
    8. else if (checkbox)
    9. {
    10. item->setChecked(receivedData[1]);
    11. }
    To copy to clipboard, switch view to plain text mode 

    I hope you get what I'm trying to say. I want to know a way to access each item without haveing to write a specific function for each register.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic access of ui items

    You can use properties for that. If you construct a map that tells you what property to use for given type of a widget (for example"text" for QLineEdit), you can check the type using QMetaObject::className() or QObject::inherits() and then use QObject::setProperty(). For lookup you can use QObject::findChildren() and QObject::objectName.

    Also take a look at QDataWidgetMapper.

Similar Threads

  1. Light items for the graphicsView
    By maverick_pol in forum Qt Programming
    Replies: 12
    Last Post: 1st November 2007, 18:51
  2. Occurance of Duplicate items in QComboBox
    By merry in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2007, 15:05
  3. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20

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.