// w is QMainWindow
QWidget* label
= w.
findChild<QLabel
*>
("label");
((QLabel*)label
)->setText
("text old");
// works fine bool res_label
= QMetaObject::invokeMethod(label,
"setText", Q_ARG
(QString,
"text new"));
// works fine, returns true
QWidget* lineEdit
= w.
findChild<QLineEdit
*>
("lineEdit");
((QLineEdit*)lineEdit
)->setText
("text old");
// works fine bool res_line_edit
= QMetaObject::invokeMethod(lineEdit,
"setText", Q_ARG
(QString,
"text new"));
// works fine, returns true
QWidget* textBrowser
= w.
findChild<QTextBrowser
*>
("textBrowser");
((QTextBrowser*)textBrowser
)->setText
("text old");
// works fine bool res_text_browser
= QMetaObject::invokeMethod(textBrowser,
"setText", Q_ARG
(QString,
"text new"));
// works fine, returns true
QWidget* pushButton
= w.
findChild<QPushButton
*>
("pushButton");
((QPushButton*)pushButton
)->setText
("text old");
// works fine bool res_push_button
= QMetaObject::invokeMethod(pushButton,
"setText", Q_ARG
(QString,
"text new"));
// NOT WORKING, RETURNS FALSE
// w is QMainWindow
QWidget* label = w.findChild<QLabel*>("label");
((QLabel*)label)->setText("text old"); // works fine
bool res_label = QMetaObject::invokeMethod(label, "setText", Q_ARG(QString, "text new")); // works fine, returns true
QWidget* lineEdit = w.findChild<QLineEdit*>("lineEdit");
((QLineEdit*)lineEdit)->setText("text old"); // works fine
bool res_line_edit = QMetaObject::invokeMethod(lineEdit, "setText", Q_ARG(QString, "text new")); // works fine, returns true
QWidget* textBrowser = w.findChild<QTextBrowser*>("textBrowser");
((QTextBrowser*)textBrowser)->setText("text old"); // works fine
bool res_text_browser = QMetaObject::invokeMethod(textBrowser, "setText", Q_ARG(QString, "text new")); // works fine, returns true
QWidget* pushButton = w.findChild<QPushButton*>("pushButton");
((QPushButton*)pushButton)->setText("text old"); // works fine
bool res_push_button = QMetaObject::invokeMethod(pushButton, "setText", Q_ARG(QString, "text new")); // NOT WORKING, RETURNS FALSE
To copy to clipboard, switch view to plain text mode
Bookmarks