[SOLVED] closing the whole application on another window
hi,
ive been trying to do this half-of-my-day already but to no avail. i want to close/quit the whole application in a child dialog but the main window isnt close.
#mainwindow
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "dialog.h"
- {
- ui->setupUi(this);
- MainWindow::openDialog();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::openDialog()
- {
- Dialog *d = new Dialog();
- if (d->exec() == 0) {
- qApp->quit();
- }
- }
the child window
- #include "dialog.h"
- #include "ui_dialog.h"
- {
- ui->setupUi(this);
- connect(ui->pushButtonReject, SIGNAL(clicked()), this, SLOT(reject()));
- connect(ui->pushButtonAccept, SIGNAL(clicked()), this, SLOT(accept()));
- }
- Dialog::~Dialog()
- {
- delete ui;
- }
so when i click the Reject button, the whole application should close but the main window is still open. what went wrong?
the Accept button should keep the main window open. how do i achieve this?
thanx.
5 replies
hello again, i came up with something like this
#mainwindow
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "dialog.h"
- {
- if (MainWindow::openDialog()) {
- ui->setupUi(this);
- } else {
- qApp->quit();
- }
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- bool MainWindow::openDialog()
- {
- Dialog *d = new Dialog(this);
- return d->exec();
- }
#child window
- #include "dialog.h"
- #include "ui_dialog.h"
- {
- ui->setupUi(this);
- connect(ui->pushButtonReject, SIGNAL(clicked()), this, SLOT(reject()));
- connect(ui->pushButtonAccept, SIGNAL(clicked()), this, SLOT(accept()));
- }
the Accept button works perfectly but the Reject button is not. there is still a small empty dialog when i click the Reject button.
I don’t know what your idea is, so not sure if that would work for you, but why don’t you try using QMessageBox [doc.qt.nokia.com] instead? You can grab the output of the buttons clicked in your app and based on that quit, save, etc….
You must log in to post a reply. Not a member yet? Register here!



