connect函数

来源:互联网 发布:数控编程方法有 编辑:程序博客网 时间:2024/04/29 13:58

接上篇关于connect函数的研究:

代码如下:

#ifndefFATHERDIALOG_H

#define FATHERDIALOG_H
#include <QDialog>
namespace Ui {
class FatherDialog;
}
class FatherDialog : public QDialog
{
    Q_OBJECT
public:
    explicit FatherDialog(QWidget *parent = 0);
    ~FatherDialog();
private slots:
    void on_pushButton_clicked();
    void showChildDialog();
private:
    Ui::FatherDialog *ui;
};
#endif // FATHERDIALOG_H


//fatherdialog.h

#include"fatherdialog.h"

#include "ui_fatherdialog.h"
#include <QMessageBox>
FatherDialog::FatherDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FatherDialog)
{
    ui->setupUi(this);
    QObject::connect(ui->childB,
                     &QPushButton::clicked,
                     this,
                     &FatherDialog::showChildDialog);
}
FatherDialog::~FatherDialog()
{
    delete ui;
}
void FatherDialog::on_pushButton_clicked()
{
    QMessageBox::information(this,"提示","<font size='26'>请告诉我为什么</font>",QMessageBox::Ok);
}
void FatherDialog::showChildDialog()
{
    QDialog * d= new QDialog(this);
    d->show();
}

//main.cpp

#include"fatherdialog.h"

#include <QApplication>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    FatherDialog w;
    w.show();
    return a.exec();


}




原创粉丝点击