PDA

View Full Version : How to Create control Array in QT4



umulingu
8th October 2009, 09:34
Hai

How to create control array like other programming languages.
and how to convert integer to string?..



int i=8;

lineEdit->setText(tr("%1").arg(i)); // its working is there any other way..

NoRulez
8th October 2009, 09:39
QString::number(i)
What do you mean with "control array like other programming languages"?

Best Regards
NoRulez

umulingu
8th October 2009, 10:04
Thanks

Control Array means group of controls with same name.

Eg.

I want 10 lineEdit in same name [lineEdit] with index



lineEdit[0]->setText("suresh");
lineEdit[1]->setText("suresh");
lineEdit[2]->setText("suresh");
.
.
.
lineEdit[9]->setText("suresh");

How to do this in QT4?

yogeshgokul
8th October 2009, 10:27
Something like this :

QDialog dlg;
QVBoxLayout *vl=new QVBoxLayout(&dlg);
dlg.setLayout(vl);
QList <QPushButton*> btnList;
for(int i=0;i<10;i++)
{
QPushButton *btn = new QPushButton("Hello", &dlg);
vl->addWidget(btn);
btnList << btn;
}
dlg.exec();

NoRulez
8th October 2009, 15:31
It's better to use an iterator like the following

QList<QLineEdit*> lineEdits;
for(QList<QLineEdit*>::iterator iter = lineEdits.begin(); iter != lineEdits.end(); ++iter) {
(*iter)->setText("Some Text");
// In Qt i think you can also use the following
// iter->setText("Some Text");
}

or an foreach loop:

foreach(QLineEdit* le, lineEdits) {
le->setText("Some Text");
}


Best Regards
NoRulez