MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QMetaMethod slot = metaObject()->method(
metaObject()->indexOfSlot("functChanged()"));
foreach (QWidget* w, findChildren<QWidget*>()) {
const QMetaObject *mo = w->metaObject();
if (!mo->userProperty().isValid() || !mo->userProperty().hasNotifySignal())
continue;
connect(w, mo->userProperty().notifySignal(), this, slot);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::functChanged()
{
qDebug() << sender();
qDebug() << "this is a signal!!!";
}
利用Qt元对象系统获取界面上发生更改的控件代码
最新推荐文章于 2021-07-07 10:50:47 发布