Hi,
you cant go to all the labels bx a loop, if thex are all defined seperatly
you have two options:
1) defining your labels yourself and the add them to your layout
|
Source code
|
1
2
3
4
5
6
7
8
9
10
|
QString myNewData("filled");
QList<QLabel*> labels;
labels.append(new QLabel("Empty1")); // your first label
labels.append(new QLabel("Empty2")); // your second label
//add this QLabel pointers to your layout
for (int i=0;i<labels.size();i++)
{
labels[i]->setText(myNewData); //this set all your labels to the content of the String
}
|
2) if you want to use the labels you have added in your designer xour could do something like:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
|
QString myNewData("filled");
QList<QLabel*> labels;
labels.append(ui->label_1); // your first label
labels.append(ui->label_2); // your second label
//add this QLabel pointers to your layout
for (int i=0;i<labels.size();i++)
{
labels[i]->setText(myNewData); //this set all your labels to the content of the String
}
|
I would prefer option one, because you can better scale it up if you need more labels in the future.
Do you know how to read Texts from files?
-If not have a look at QTextstream
Hope this helps,
slevon