
Originally Posted by
Wolletje
I am a newby at Qt
I have been searching extensively in the large amount of Qt-documentation and got lost.
In Qt Creator lineEdits are named as lineEdit, lineEdit_2 etc
Can anyone tell me if it is possible to create QLineEdit widgets with names as lineEdit[i] which can be called by a for-loop.
ui->lineEdit[i]-> setText(something[i]);
(Reference to) a short simple example would be very welcome.
You can use this code: (Qt example in QSignalMapper):
for (int i = 0; i < texts.size(); ++i) {
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(button, texts[i]);
gridLayout->addWidget(button, i / 3, i % 3);
}
QGridLayout *gridLayout = new QGridLayout;
for (int i = 0; i < texts.size(); ++i) {
QPushButton *button = new QPushButton(texts[i]);
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(button, texts[i]);
gridLayout->addWidget(button, i / 3, i % 3);
}
To copy to clipboard, switch view to plain text mode
Bookmarks