想要实现点击一个普通按钮,得到和点击关闭程序的按钮一样的效果。一定要closeEvent函数被执行。

关键代码段:
dialog.h

protected:
    virtual void closeEvent(QCloseEvent *event);
private slots:
    void on_pushButton_clicked();

dialog.cpp

void Dialog::closeEvent(QCloseEvent *event)
{
    qDebug() << " closeEvent happened. ";
    QDialog::closeEvent(event);
}

void Dialog::on_pushButton_clicked()
{
    QCloseEvent event; // We can read super class QEvent, there are more event types.
    QCoreApplication::sendEvent( this, &event );
}


分类: C plus plus

发表评论

电子邮件地址不会被公开。 必填项已用*标注