Should I choose the label or other ui object before runtime? Can I choose them on runtime?
What I mean is :
Should I write:
Code:
for (int i = 0; i < 5 ; i++) { }
But I want to write as:
Is it possible to write in this way?
Printable View
Should I choose the label or other ui object before runtime? Can I choose them on runtime?
What I mean is :
Should I write:
Code:
for (int i = 0; i < 5 ; i++) { }
But I want to write as:
Is it possible to write in this way?
You can't do it like you wrote it.
But, there are a couple of techniques that do let you do this.
1. Use the name of the object.
2. Create a list of objects.
EDIT:
oops, beat to it by tbscope.
No this is not possible the way you wrote it, as you will find out if you try to compile it.
What you can do is put all your labels in a container:
Code:
QVector<QLabel*> vecLabels; vecLabels.push_back(ui->label_0); vecLabels.push_back(ui->label_1); ... for (int i = 0; i < 5 ; i++) { }
@tbscope , @high_flyer
Thank you for your replies.
@high_flyer
Thank you for your example, it helped a lot.