【发布时间】:2012-03-27 16:28:58
【问题描述】:
我在 Qt 中创建了一个非常简单的 GUI 项目,如下所示:
主要:
#include <QApplication>
#include "dialog.h"
int main(int c, char* v[])
{
QApplication app(c,v);
Dialog* d = new Dialog;
d->show();
app.exec();
}
dialog.h:
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include "ui_dialog.h"
#include "progress_dialog.h"
class Dialog : public QDialog, private Ui::Dialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
private:
progress_dialog* progress_dialog_;
public slots:
void create_and_show_progress_dialog();
void delete_progress_dialog();
};
#endif // DIALOG_H
dialog.cpp:
#include "dialog.h"
#include "ui_dialog.h"
#include <QMessageBox>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),progress_dialog_(new progress_dialog)
{
setupUi(this);
connect(pushButton,SIGNAL(clicked()),this,SLOT(create_and_show_progress_dialog()));
connect(progress_dialog_,SIGNAL(rejected()),this,SLOT(delete_progress_dialog()));
}
void Dialog::create_and_show_progress_dialog()
{
if (!progress_dialog_)
progress_dialog_ = new progress_dialog;
progress_dialog_->exec();
}
void Dialog::delete_progress_dialog()
{
delete progress_dialog_;
progress_dialog_ = nullptr;
QMessageBox::information(this,"Progress destroyed","I've just destroyed progress");
}
Dialog::~Dialog()
{
}
进度对话框:
#ifndef PROGRESS_DIALOG_H
#define PROGRESS_DIALOG_H
#include "ui_progress_dialog.h"
class progress_dialog : public QDialog, private Ui::progress_dialog
{
Q_OBJECT
public:
explicit progress_dialog(QWidget *parent = 0);
public slots:
void exec_me();
};
#endif // PROGRESS_DIALOG_H
progress_dialog.cpp:
#include "progress_dialog.h"
progress_dialog::progress_dialog(QWidget *parent) :
QDialog(parent)
{
setupUi(this);
}
所以问题是,在运行这个应用程序并按下主对话框上的 push_button 后,progress_dialog 正在显示。单击连接到拒绝槽的progress_dialog 上的push_buttong 后,此对话框正在关闭并显示消息:QMessageBox::information(this,"Progress destroy","Ive just destroyed progress");
但是当我第二次这样做时(按下主对话框上的按钮,然后关闭 progress_dialog)没有显示任何消息。尝试对此进行调试并设置断点:
void Dialog::delete_progress_dialog()
{
delete progress_dialog_;//HERE BREAKPOINT WAS PLACED
progress_dialog_ = nullptr;
QMessageBox::information(this,"Progress destroyed","I've just destroyed progress");
}
但是这个断点只是第一次被命中,之后没有命中这个断点。
怎么回事?
【问题讨论】: