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

connect函数connect函数connect函数

代码如下:

#ifndef FATHERDIALOG_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();


}






相关文章:

  • 2021-12-30
  • 2021-07-05
  • 2021-09-02
  • 2022-01-15
  • 2021-05-30
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-23
  • 2021-05-27
  • 2022-12-23
  • 2021-07-28
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案