PDA

View Full Version : Variable variable names



KeineAhnung
22nd June 2014, 16:39
Hi,

are there variable variable names in Qt? I tried to search for it but I did not really know how to and so I found nothing. I have a php background and there I could do this (http://php.net/manual/en/language.variables.variable.php). Can I do something similar in Qt?

My problem is that I have a class with several properties and a variable that tells me which property is interesting at the moment. In stead of writing a lot of if statements I would rather directly go the value by stating className.interestingValue.

Here is an example. I got the class car. Within that class have several properties like car.door = 4 and car.maxSpeed = 200 etc. On the other hand I got a variable testValue = "door". How can I get the number of doors now from my class car object without using if-statements? Like log.append("Your result is: "+audi.testValue.toStr());

Thanks

Lesiok
22nd June 2014, 17:14
Read about property system (http://qt-project.org/doc/qt-4.8/properties.html)

Infinity
22nd June 2014, 19:00
You can also use QMap or std::map.