PDA

View Full Version : Array of QLabel



kavinsiva
14th August 2009, 07:22
Hi,

Can i have array of QLabel?
if it possible means pls give me the syntax to that one
Bye

wysota
14th August 2009, 07:35
You can have an array of pointers to QLabel.


QList<QLabel*> array;

kavinsiva
14th August 2009, 13:12
Hi,

In case i have a array of QLabel ,then how do add the text within it ?
Bye..

spirit
14th August 2009, 13:23
QList<QLabel *> labels;
for (int i = 0; i < 10; ++i)
labels << new QLabel(this);
...
for (int i = 0; i < 10; ++i)
labels.at(i)->setText(QString::number(i));
...

PaceyIV
14th August 2009, 20:13
I do with a vector like this:



QLabel *lbArr[SIZE];

for (int i = 0; i < SIZE; ++i)
lbArr[i] = new QLabel(this);


for (int i = 0; i < SIZE; ++i)
lbArr[i]->setText( tr("Label n. %1").arg(i) );

PaceyIV
14th August 2009, 20:17
If you know how many Label you need and are not too I think is a better idea use a vector instead of a List.

In that case see this http://www.qtcentre.org/forum/p-qlabel-post113331/postcount3.html

Walter
15th August 2009, 07:19
Get used to QList and the other Qt classes - they are very convenient and you never will have size problems like with arrays in the post above