I need a method helping me, to reach variables named like ‘comboBox1’, ‘comboBox2’ etc each by each in a loop. I’d like to change code like:
//proceed comboBox1 //proceed comboBox2 //proceed comboBox3 //proceed comboBox4 //proceed comboBox5 //proceed comboBox6
Into:
for (int i = 1; i < numberOfBoxes; i++) { //proceed comboBox(i) }
I tried to find somthing like ‘eval’, but google didn’t give anything matching. I also tried preprocessing the name with operator ## but it seems there’s no way to put current integer value to the macro.
The simplest solution is to put them all in an array and iterator over that:
Now you can iterate over combos. The main problem is that c++ doesn’t have reflection. So you can’t generated a string at runtime and get the address of an object or function like you can in some other languages.
EDIT: I just saw that you are using Qt. In that case, you should use:
or
This lets you get a list based on runtime generated names. For example:
then you can just iterate over that!