Combine number and text
I have a this code right now:
Code:
QLabel *label = new QLabel("text", this, "name"); The question is really easy (I think). I don't know how many of these I will need, so I would get the number of labels at runtime and then I would like to call them "name1", "name2", etc by just using a for-loop, that would produce like: Code:
for (int i = 0; i<num; i++) |
A simple solution would be to have a function that returns the next label name.
Untested code: Code:
const std::string& next_label = get_next_label_name(); Code:
std::string get_next_label_name() |
I still have the problem with the variable-name. This one is really important. Is there even a solution to this? Can I create like three variables called var1, var2, var3 with a for-loop, without using arrays.
|
You simply cannot do it that way.
You can, however, use an array or a QList of pointers to QLabel's. An array would look something like this: Code:
QLabel *labels[100]; |
All times are GMT -5. The time now is 01:11 PM. |