[SOLVED] problem with setting QLineEdit text inside QFormLayout row?
-
Hi, I've a problem with setting a QLineEdit text which is inside
a specific row(that contains also a QLabel) on a QFormLayout:@void set_formlayout_row_linedit_text(QFormLayout* qfl, int row, char* text){
QLayoutItem *itm = qfl->itemAt(row,QFormLayout::FieldRole);
if(dynamic_cast<QLineEdit *>(itm)){
QLineEdit * qle = dynamic_cast<QLineEdit *>(itm);
qle->setText(text);
}
}@because the text has not being set yet when I tested that function on my program,
please help me to solve the problem. -
please help it's urgent! thanks.
-
Are you sure that a results of qfl->itemAt(row,QFormLayout::FieldRole); and dynamic_cast<QLineEdit *>(itm) are not NULL.
I think you need to use "QLayoutItem::widget()":http://qt-project.org/doc/qt-5/qlayoutitem.html#widget to get an actual widget in a layout item.
-
I would try it with qobject_cast:
@void set_formlayout_row_linedit_text(QFormLayout* qfl, int row, char* text){
QLayoutItem *itm = qfl->itemAt(row, QFormLayout::FieldRole);
QLineEdit * qle = qobject_cast<QLineEdit *>(itm->widget());
if (qle){
qle->setText(text);
}
}@ -
that really helps, thank you very much.