PDA

View Full Version : Quit all applications



dragon
21st February 2012, 19:23
Hello Anyone,

I have Qt 4-7
I have a MainWindow and a Dialog for login.
In the Dialog i have 2 pushbuttons.
One pushbutton called Start is for Ok Signal to get to the MainWindow.
One pushbutton called Cancel is for Reject Signal to close the Dialog and for quit the MainWindow.
The point is i want with the Cancel pushbutton from Dialog to quit the MainWindow.
The Dialog login starts direct.


mainwindow.cc


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

productDialog *dlg = new productDialog(this);
dlg->exec(); //This starts the Dialog login
etc .....



I have implement a Timer but if i click on the Cancel pushbutton in Dialog login i see still for halve second the MainWindow and this i don't want to see.
main.cc


#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
QTimer::singleShot(0,qApp, SLOT(quit())); //I have used a Timer
return a.exec();
}


Thanks in advance.

ChrisW67
21st February 2012, 22:08
If you don't want the main window if the user cancels the dialog then don't construct or show it in the first place. For example:


#include <QtGui/QApplication>
#include "mainwindow.h"
#include "productdialog.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

productDialog dlg;
int ret = dlg.exec();
if (ret == QDialog::Accepted)
MainWindow w;
w.show();
return a.exec();
}
return 0;
}

dragon
22nd February 2012, 18:46
Hello ChrisW67,

Thanks for your post.
It workd fine now.