Access the members of dynamic form
How do I access an existing QLineEdit in a form generated automatically with QUiLoader? For example, to get your content.
@ MyWidget::MyWidget(QWidget *parent)
QWidget *myWidget = loader.load(&file, this);
QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(myWidget); setLayout(layout); }
Assuming that there is a QLineEdit in MyWidget. How to access it?
You can try using some thing like this.
QList<QLineEdit*> edits = myWidget->findChildren<QLineEdit*>();
How to get a specific QLineEdit on the list?
Suppose I want to access the QLineEdit that contains the server ip. How do I know what position is he?
Give an object name to the QLineEdit then you can search using it
In addition to what SGaist said, you can use the specific API
@QList<QWidget *> widgets = parentWidget.findChildren<QWidget *>("widgetname");@
You can look at the findChildren(..) API in Qt Documentation. It has more details.
I wanted a way to catch all
@QList<QLineEdit*> edits = myWidget->findChildren<QLineEdit*>();@
And after finding a specific QLineEdit in list. Thus I think I save a few lines of code.
[quote author="Exotic_Devel" date="1408902797"] after finding a specific QLineEdit in list. Thus I think I save a few lines of code.[/quote]
Then for such case . you have following approaches.
hope it helps you
What wrong with:
@QLineEdit *lineEdit = parentWidget->findChild<QLineEdit *>("myFunkyComboBox");@
Sorry, that was an editing mistake
I'm using 'findChildren' to put all QLineEdit in a list and pass it as a parameter to a method. However, I do not know how to extract a specific QLineEdit the list to be able to manipulate. eg
@lineedits = connecdiag->findChildren<QLineEdit*>(QString(), Qt::FindDirectChildrenOnly);@
How to catch a QLineEdit called 'qle_port' that is in
Why not search directly for QLineEdits having this name ? e.g.
ineedits = connecdiag->findChildren<QLineEdit*>("qle_port", Qt::FindDirectChildrenOnly);@