Results 1 to 3 of 3

Thread: Quit all applications

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Quit all applications

    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
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. productDialog *dlg = new productDialog(this);
    8. dlg->exec(); //This starts the Dialog login
    9. etc .....
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. QTimer::singleShot(0,qApp, SLOT(quit())); //I have used a Timer
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Quit all applications

    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:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include "productdialog.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. productDialog dlg;
    10. int ret = dlg.exec();
    11. if (ret == QDialog::Accepted)
    12. MainWindow w;
    13. w.show();
    14. return a.exec();
    15. }
    16. return 0;
    17. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Quit all applications

    Hello ChrisW67,

    Thanks for your post.
    It workd fine now.

Similar Threads

  1. Replies: 2
    Last Post: 1st August 2011, 06:30
  2. Why my application quit?
    By yxtx1984 in forum Newbie
    Replies: 1
    Last Post: 7th February 2010, 05:46
  3. QThread quit() issue.
    By rokkamraja in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2009, 16:34
  4. Quit action in MainWindow
    By Backslash in forum Newbie
    Replies: 9
    Last Post: 31st July 2007, 21:21
  5. why teminate only works with quit() and not any other
    By srikpen in forum Qt Programming
    Replies: 2
    Last Post: 28th January 2007, 12:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.