Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to exit app?
Forum Updated to NodeBB v4.3 + New Features

How to exit app?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • chaochaoC Offline
    chaochaoC Offline
    chaochao
    wrote on last edited by
    #1

    I create a button and connet to slot exitApp;

     QPushButton *exitbutton  = new QPushButton(tr("exit"),menu);
     connect(exitbutton, SIGNAL(clicked(bool)),this,SLOT(exitApp()));
    
    void GameView::exitApp()
    {
        qDebug()<<"exitApp";
        QCoreApplication::exit(0);
    }
    

    but what is the matter is I must click exitbutton twice,the app can exit;In other words,APP will debug "exitApp" twice;

    R raven-worxR 2 Replies Last reply
    0
    • chaochaoC chaochao

      I create a button and connet to slot exitApp;

       QPushButton *exitbutton  = new QPushButton(tr("exit"),menu);
       connect(exitbutton, SIGNAL(clicked(bool)),this,SLOT(exitApp()));
      
      void GameView::exitApp()
      {
          qDebug()<<"exitApp";
          QCoreApplication::exit(0);
      }
      

      but what is the matter is I must click exitbutton twice,the app can exit;In other words,APP will debug "exitApp" twice;

      R Offline
      R Offline
      Rohith
      wrote on last edited by
      #2

      @chaochao

      May be you can try this...!

      qApp->closeAllWindows();

      chaochaoC 1 Reply Last reply
      0
      • chaochaoC chaochao

        I create a button and connet to slot exitApp;

         QPushButton *exitbutton  = new QPushButton(tr("exit"),menu);
         connect(exitbutton, SIGNAL(clicked(bool)),this,SLOT(exitApp()));
        
        void GameView::exitApp()
        {
            qDebug()<<"exitApp";
            QCoreApplication::exit(0);
        }
        

        but what is the matter is I must click exitbutton twice,the app can exit;In other words,APP will debug "exitApp" twice;

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @chaochao
        have you reimplemented any closeEvent() handlers in your application or smiliar?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        chaochaoC 1 Reply Last reply
        0
        • R Rohith

          @chaochao

          May be you can try this...!

          qApp->closeAllWindows();

          chaochaoC Offline
          chaochaoC Offline
          chaochao
          wrote on last edited by
          #4

          @Rohith it can close current window,but it will display a untitled window. i do not know where the untitled window came from

          1 Reply Last reply
          0
          • raven-worxR raven-worx

            @chaochao
            have you reimplemented any closeEvent() handlers in your application or smiliar?

            chaochaoC Offline
            chaochaoC Offline
            chaochao
            wrote on last edited by
            #5

            @raven-worx yes ,i have reimpemented closeEvent.like this```
            void GameView::closeEvent(QCloseEvent *event)
            {
            if(_isGameStart)
            {
            int r = QMessageBox::warning(this,tr("Close"),
            tr("Score is %1 \n"
            "Would you want to close game?").arg(_score->toPlainText().toInt()),
            QMessageBox::Ok|QMessageBox::Cancel);
            if(r==QMessageBox::Ok)
            event->accept();
            else
            event->ignore();
            }
            else
            event->ignore();
            }

            but it  belongs to GameView; code in the question is in a dialog.
            whole project like this:
            class GameView:public QGraphicsView
            {
            public:
                GameView();
             void initGame();
            }
            in .cpp:
            GameView::GameView()
                :_isGameStart(false),_gameLevel(1)
            { 
                initGame();
            }
            void GameView::initGame()
            {
                 QDialog *menu = new QDialog(this);
                QPushButton *exitbutton  = new QPushButton(tr("Exit"),menu);
               connect(exitbutton, SIGNAL(clicked(bool)),this,SLOT(exitApp()));
            }
            raven-worxR 1 Reply Last reply
            0
            • chaochaoC chaochao

              @raven-worx yes ,i have reimpemented closeEvent.like this```
              void GameView::closeEvent(QCloseEvent *event)
              {
              if(_isGameStart)
              {
              int r = QMessageBox::warning(this,tr("Close"),
              tr("Score is %1 \n"
              "Would you want to close game?").arg(_score->toPlainText().toInt()),
              QMessageBox::Ok|QMessageBox::Cancel);
              if(r==QMessageBox::Ok)
              event->accept();
              else
              event->ignore();
              }
              else
              event->ignore();
              }

              but it  belongs to GameView; code in the question is in a dialog.
              whole project like this:
              class GameView:public QGraphicsView
              {
              public:
                  GameView();
               void initGame();
              }
              in .cpp:
              GameView::GameView()
                  :_isGameStart(false),_gameLevel(1)
              { 
                  initGame();
              }
              void GameView::initGame()
              {
                   QDialog *menu = new QDialog(this);
                  QPushButton *exitbutton  = new QPushButton(tr("Exit"),menu);
                 connect(exitbutton, SIGNAL(clicked(bool)),this,SLOT(exitApp()));
              }
              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @chaochao said:

              void GameView::initGame()
              {
              QDialog *menu = new QDialog(this);
              QPushButton *exitbutton = new QPushButton(tr("Exit"),menu);
              connect(exitbutton, SIGNAL(clicked(bool)),this,SLOT(exitApp()));
              }

              this code doesn't make sense.
              You are creating a dangling QDialog (window) but never show it.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              chaochaoC 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @chaochao said:

                void GameView::initGame()
                {
                QDialog *menu = new QDialog(this);
                QPushButton *exitbutton = new QPushButton(tr("Exit"),menu);
                connect(exitbutton, SIGNAL(clicked(bool)),this,SLOT(exitApp()));
                }

                this code doesn't make sense.
                You are creating a dangling QDialog (window) but never show it.

                chaochaoC Offline
                chaochaoC Offline
                chaochao
                wrote on last edited by
                #7

                @raven-worx i also find it.but how to solve?

                raven-worxR 1 Reply Last reply
                0
                • chaochaoC chaochao

                  @raven-worx i also find it.but how to solve?

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @chaochao
                  well when you never show it you can simply remove the code ;)

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  chaochaoC 1 Reply Last reply
                  0
                  • raven-worxR raven-worx

                    @chaochao
                    well when you never show it you can simply remove the code ;)

                    chaochaoC Offline
                    chaochaoC Offline
                    chaochao
                    wrote on last edited by
                    #9

                    @raven-worx remove?

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved