自定义信号与槽:
1.在dialog的头文件添加
public slots:
void showChildDialog();
2.右键代码,找到"Refactor",在cpp生成showChildDialog()函数
void Dialog::showChildDialog()
{
QDialog * dialog = new QDialog();
dialog->show();
}
3.在构造函数内添加connect语句
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
connect(ui->showChildButton,&QPushButton::clicked,this,
&Dialog::showChildDialog);
}
本文展示了在Qt中如何自定义信号和槽。首先在dialog头文件声明`showChildDialog()`作为公共槽,然后通过右键重构生成实现。在Dialog的构造函数里,将`showChildButton`的点击信号连接到`showChildDialog()`槽,当按钮被点击时显示新的QDialog。
2141

被折叠的 条评论
为什么被折叠?



