Search code examples
c++qtoopparent-childqlineedit

QLineEdit and findChild()


I am trying to set the text of a line edit that is found using findChild()

mainwindow.cpp

void MainWindow::setValue(QString line, QString value){
    QLineEdit * edit = centralWidget()->findChild<QLineEdit *>(line);
    edit.setText(value);
}

However, I get an error on edit.setText(value); saying left of .setText must be class/struct/union.

How do I properly set the text of the child name line to be value?


Solution

  • You need to use the -> operator as edit is a pointer:

    edit->setText(value);