Qt Designer
Qt Deisigner
pushButton = new QPushButton(centralWidget); pushButton->setObjectName(QStringLiteral("pushButton")); pushButton->setGeometry(QRect(60, 40, 75, 23)); pushButton->setText("ok");
mainwindow.cpp
QPushButton * pushButton; QWidget * centralWidget =ui->centralWidget; pushButton = new QPushButton(centralWidget); pushButton->setObjectName(QStringLiteral("pushButton")); pushButton->setGeometry(QRect(60, 40, 75, 23)); pushButton->setText("ok");
Qt Designermainwindow.cpp
void MainWindow::on_pushButton_clicked() { }
ui_mainwindow.h
所以需要自己进行信号与槽的关联。
connect(pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));
文章来源: QT:代码动态管理控件