Results 1 to 3 of 3

Thread: qApp->quit() can not work

  1. #1
    Join Date
    Oct 2013
    Posts
    8
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default qApp->quit() can not work

    i create qdialog in my main window,
    and dialog has two button ,ok and cancel

    i hope when click cancel button ,my application can quit

    in my dialog class,there are two signal :LoginOkClick & LoginCancelClick,
    and main window has two slot to receive this two signal : StartTest & StopApp
    qApp->quit() is in slot StopApp.

    when i click cancel button ,application not quit , i ensure the api "qApp->quit()" was called.
    But when i click ok (it will do dialog show & dialog exec again)and then click cancel ,my application quit success

    can anyone tell me why?

    My code
    =======================MainWindow================= ===============

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    mLoginDlg = new LoginDlg();
    connect(mLoginDlg,SIGNAL(LoginOkClick()),this,SLOT (StartTest()));
    connect(mLoginDlg,SIGNAL(LoginCancelClick()),this, SLOT(StopApp()));
    mLoginDlg->exec();
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    //slots---------------------
    void MainWindow::StopApp()
    {

    qDebug()<<"StopApp"<<endl;
    qApp->quit();
    }

    void MainWindow::StartTest()
    {
    qDebug()<<"StartTest"<<endl;
    mLoginDlg->show();
    mLoginDlg->exec();
    }


    ==========================LoginDlg================ ====================
    LoginDlg::LoginDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LoginDlg)
    {
    ui->setupUi(this);
    Init();
    }

    LoginDlg::~LoginDlg()
    {
    delete ui;
    }


    void LoginDlg::Init()
    {

    //slot init----------------------------------
    QPushButton* bt_ok = ui->btbx_main->button(QDialogButtonBox::Ok);
    QPushButton* bt_cancel= ui->btbx_main->button(QDialogButtonBox::Cancel);
    connect(bt_ok,SIGNAL(clicked()),this,SLOT(onOkButt onClick()));
    connect(bt_cancel,SIGNAL(clicked()),this,SLOT(onCa ncelButtonClick()));
    }

    void LoginDlg::closeEvent(QCloseEvent * e)
    {
    emit LoginCancelClick();
    }

    //slots---------------------
    void LoginDlg:nOkButtonClick()
    {

    emit LoginOkClick();

    }

    void LoginDlg:nCancelButtonClick()
    {
    emit LoginCancelClick();
    }
    Last edited by xstream71; 15th October 2013 at 07:44.

  2. #2
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: qApp->quit() can not work

    quit() method use event mecanism, if it's do nothing the first call, your event loop is probably not running.
    Show you main.c , exec() is a blocking function, so everything after your MainWindow constructor call will not be execute before the modal dialog is closed.

  3. The following user says thank you to nix for this useful post:

    xstream71 (15th October 2013)

  4. #3
    Join Date
    Oct 2013
    Posts
    8
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: qApp->quit() can not work

    Thanks.
    I know now.

Similar Threads

  1. qApp->quit() deletes all its children?
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 7th April 2012, 23:32
  2. Replies: 2
    Last Post: 1st August 2011, 06:30
  3. Qt-based dll: qApp = 0 !!
    By Elder Orb in forum Qt Programming
    Replies: 6
    Last Post: 14th September 2010, 16:15
  4. qApp is not accesible
    By URPradhan in forum Qt Programming
    Replies: 5
    Last Post: 10th July 2009, 03:23
  5. Quit, Exit qApp (program) if error?
    By Arsenic in forum Newbie
    Replies: 13
    Last Post: 30th September 2008, 12:59

Tags for this Thread

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.