PDA

View Full Version : Dynamic access of ui items



Matze-o
5th November 2008, 10:43
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).



receivedData = receive();
register = receivedData[0];
item = lookup(register);
if (lineEdit)
{
item->setText(receivedData[1]);
}
else if (checkbox)
{
item->setChecked(receivedData[1]);
}


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.

jacek
6th November 2008, 23:13
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.