[SOLVED]Loop for QLabels?
-
hi,
i need to create a custom number of Labelse.g.
@ for (int i=0; i<10; i++){
QLabel *label_i;
label_i = new QLabel;
}@I know, this is not working, but just to show what I mean.
Is this somehow possible to do it?
i guess it is done using something like this
@QLabel *label_("%1"), i;@
-
[quote author="messi" date="1354634051"]Ui, a question popped up in my mind.
How good is your knowledge about C/C++?
[/quote]i passed the first two semester -_-
alright, I solved it.
I didnt know, you can use an array for everything
e.g.
@QLabel *label[10];@I thought this simplicity, just shouldnt work
thx anyway
and for renaming i used this, what was actually just copied
@QLabel *label[10];@
@for (int i=0; i< 10; i++){
label[i] = new QLabel;
label[i]->setText(QString("%1").arg(i));
label[i]->show(); //Test purpose
}@ -
Your idea is typical for someone who programs in general with script languages, like perl,phyton etc.
I think there you can do this approach but not in C++.Put the QLabel array as an member in your class so that you can access it later if you need it.
And do not forget to initialize the array.
@for(int i=0; i<5; ++i)
mLabelArray[i] = new QLabel;@