简体   繁体   中英

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 ?

您需要使用->运算符,因为edit是一个指针:

edit->setText(value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM