Reputation:
This is simple structure I have:
QVBoxLayout called switchesLayout_2 | |\_ QHBoxLayout | | | |\_ QLabel | \_ QEditLine | |\_ QHBoxLayout | | | |\_ QLabel | \_ QEditLine and so on...
I need to get a text from every QEditLine in switchesLayout_2. I've tried this code:
for(int i = 0; i < switchesAmount; i++) { req += " " + ui->switchesLayout_2->itemAt(i)->layout()->itemAt(1)->widget()->text(); }I keep getting: 'class QWidget' has no member named 'text'
What can I do? Thanks!
Upvotes: 0
Views: 1138
Reputation: 5207
The easiest way to do this is to use the QObject::findChildren()
method on the actual parent widget.
const QList<QLineEdit*> lineEdits = ui->widgetThatHasSwitchesLayout_2->findChildren<QLineEdit*>();
for (QLineEdit *lineEdit : lineEdits) {
req += " " + lineEdit->text();
}
Upvotes: 1