Qt QMessageBox - 关闭应用程序而不仅仅是消息框
Qt QMessageBox - closes application instead of just message box
创建了一个 QMessageBox,当我在我的应用程序上按下 'Start' 按钮时它会出现。
按下任一按钮(确定或取消)时 - 我希望消息框关闭 - 但应用程序保持打开状态。
不幸的是,当我点击确定或取消时,整个应用程序将关闭。有什么建议吗?
J
这是我的代码:
Main.cpp:
#include "openingdialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
Opening Dialog:
patientsetup::patientsetup(QWidget *parent) :
QDialog(parent),
ui(new Ui::patientsetup)
{
ui->setupUi(this);
connect(ui->okButton, SIGNAL(clicked()), this, SLOT(confirmButtonClicked()));
connect(ui->ACSMode, SIGNAL(clicked()), this, SLOT(ACSButtonClicked()));
connect(ui->PromptMode, SIGNAL(clicked()), this, SLOT(PMPSAIButtonClicked()));
connect(ui->FullMode, SIGNAL(clicked()), this, SLOT(PMPSFullbuttonClicked()));
}
void patientsetup::PMPSAIButtonClicked()
{
direct = new pmps_f(this);
direct->setData(patient, ui->Weight->value(), ui->Height->value(), lbmvalue, bsavalue, gender);
direct->show();
}
pmps_f MainWindow
pmps_f::pmps_f(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::pmps_f)
{
ui->setupUi(this);
connect(ui->startbutton,SIGNAL(clicked(bool)), this, SLOT(start()));
}
void pmps_f::start()
{
QMessageBox msgBox;
msgBox.setText("Pressing continue will start the process with the process");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
int ret = msgBox.exec();
switch(ret) {
case QMessageBox::Ok:
msgBox.close();
break;
case QMessageBox::Cancel:
msgBox.close();
break;
}
}
完整代码:
pmps_f::pmps_f(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::pmps_f)
{
ui->setupUi(this);
connect(ui->startbutton,SIGNAL(clicked(bool)), this, SLOT(start()));
}
pmps_f::~pmps_f()
{
delete ui;
}
//public function that pulls the Patient data from the patientsetup.ui interface
void pmps_f::setData(const QString &fileName, const double &weightValue, const double &heightValue, const double &lbmValue, const double &bsaValue, const QString &genderName)
{
ui->file->setText(fileName);
ui->weight->setText(QString::number(weightValue));
ui->height->setText(QString::number(heightValue));
ui->lbm->setText(QString::number(lbmValue));
ui->bsa->setText(QString::number(bsaValue));
ui->gender->setText(genderName);
}
//Sedation start confirmation check
void pmps_f::start()
{
QMessageBox msgBox;
msgBox.setText("Pressing continue will start the sedation process");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
int ret = msgBox.exec();
switch(ret) {
case QMessageBox::Ok:
break;
case QMessageBox::Cancel:
break;
}
}
我设法使用以下方法解决了问题:
setQuitOnLastWindowClosed(假);
但是 - 现在程序在按下 window 'x' 按钮时无法正常退出...
有人可以帮忙吗?
创建了一个 QMessageBox,当我在我的应用程序上按下 'Start' 按钮时它会出现。
按下任一按钮(确定或取消)时 - 我希望消息框关闭 - 但应用程序保持打开状态。
不幸的是,当我点击确定或取消时,整个应用程序将关闭。有什么建议吗?
J
这是我的代码:
Main.cpp:
#include "openingdialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
Opening Dialog:
patientsetup::patientsetup(QWidget *parent) :
QDialog(parent),
ui(new Ui::patientsetup)
{
ui->setupUi(this);
connect(ui->okButton, SIGNAL(clicked()), this, SLOT(confirmButtonClicked()));
connect(ui->ACSMode, SIGNAL(clicked()), this, SLOT(ACSButtonClicked()));
connect(ui->PromptMode, SIGNAL(clicked()), this, SLOT(PMPSAIButtonClicked()));
connect(ui->FullMode, SIGNAL(clicked()), this, SLOT(PMPSFullbuttonClicked()));
}
void patientsetup::PMPSAIButtonClicked()
{
direct = new pmps_f(this);
direct->setData(patient, ui->Weight->value(), ui->Height->value(), lbmvalue, bsavalue, gender);
direct->show();
}
pmps_f MainWindow
pmps_f::pmps_f(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::pmps_f)
{
ui->setupUi(this);
connect(ui->startbutton,SIGNAL(clicked(bool)), this, SLOT(start()));
}
void pmps_f::start()
{
QMessageBox msgBox;
msgBox.setText("Pressing continue will start the process with the process");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
int ret = msgBox.exec();
switch(ret) {
case QMessageBox::Ok:
msgBox.close();
break;
case QMessageBox::Cancel:
msgBox.close();
break;
}
}
完整代码:
pmps_f::pmps_f(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::pmps_f)
{
ui->setupUi(this);
connect(ui->startbutton,SIGNAL(clicked(bool)), this, SLOT(start()));
}
pmps_f::~pmps_f()
{
delete ui;
}
//public function that pulls the Patient data from the patientsetup.ui interface
void pmps_f::setData(const QString &fileName, const double &weightValue, const double &heightValue, const double &lbmValue, const double &bsaValue, const QString &genderName)
{
ui->file->setText(fileName);
ui->weight->setText(QString::number(weightValue));
ui->height->setText(QString::number(heightValue));
ui->lbm->setText(QString::number(lbmValue));
ui->bsa->setText(QString::number(bsaValue));
ui->gender->setText(genderName);
}
//Sedation start confirmation check
void pmps_f::start()
{
QMessageBox msgBox;
msgBox.setText("Pressing continue will start the sedation process");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
int ret = msgBox.exec();
switch(ret) {
case QMessageBox::Ok:
break;
case QMessageBox::Cancel:
break;
}
}
我设法使用以下方法解决了问题:
setQuitOnLastWindowClosed(假);
但是 - 现在程序在按下 window 'x' 按钮时无法正常退出...
有人可以帮忙吗?