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. Qt app doesn't close properly (still visible in task manager)
Forum Updated to NodeBB v4.3 + New Features

Qt app doesn't close properly (still visible in task manager)

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 3.5k Views 2 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.
  • H Offline
    H Offline
    hobbyProgrammer
    wrote on 8 Nov 2019, 13:10 last edited by hobbyProgrammer 11 Aug 2019, 14:21
    #1

    I've written an application, but when I use the close button on the right corner to close the app, the window is invisible, but it's still in my task manager. I am talking about the buttons that Qt provides when you create a window.

    I have an app with 3 windows. You need to go through the first window to get the second and you need to get through the second window to get the third. So I'm calling 2 hides, but I would think that if you'd press the close button it would close the entire app.
    Is there anyone else having the same issues and if so, how can I solve this?

    I've set a breakpoint to return a.exec(), but it doesn't go there.

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        Login login;
        login.show();
    
        qApp->setQuitOnLastWindowClosed(false);
    
        return a.exec();
    }
    

    could it be the setQuitOnLastWindowClosed(false) that prevents it from closing?
    I need that line to not let my app crash when I show a QMessageBox.

    J P 2 Replies Last reply 8 Nov 2019, 13:40
    0
    • H hobbyProgrammer
      8 Nov 2019, 13:10

      I've written an application, but when I use the close button on the right corner to close the app, the window is invisible, but it's still in my task manager. I am talking about the buttons that Qt provides when you create a window.

      I have an app with 3 windows. You need to go through the first window to get the second and you need to get through the second window to get the third. So I'm calling 2 hides, but I would think that if you'd press the close button it would close the entire app.
      Is there anyone else having the same issues and if so, how can I solve this?

      I've set a breakpoint to return a.exec(), but it doesn't go there.

      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          Login login;
          login.show();
      
          qApp->setQuitOnLastWindowClosed(false);
      
          return a.exec();
      }
      

      could it be the setQuitOnLastWindowClosed(false) that prevents it from closing?
      I need that line to not let my app crash when I show a QMessageBox.

      J Offline
      J Offline
      JonB
      wrote on 8 Nov 2019, 13:40 last edited by
      #2

      @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

      qApp->setQuitOnLastWindowClosed(false)

      does exactly what it says on the tin! Of course it prevents the application from automatically exiting when the last window is closed! So you'll get the behaviour you describe.

      I need that line to not let my app crash when I show a QMessageBox.

      No idea what you mean. I cannot imagine you would want to disable auto-closing on last window close, especially as you're complaining about just that keep-running behaviour.

      1 Reply Last reply
      3
      • H hobbyProgrammer
        8 Nov 2019, 13:10

        I've written an application, but when I use the close button on the right corner to close the app, the window is invisible, but it's still in my task manager. I am talking about the buttons that Qt provides when you create a window.

        I have an app with 3 windows. You need to go through the first window to get the second and you need to get through the second window to get the third. So I'm calling 2 hides, but I would think that if you'd press the close button it would close the entire app.
        Is there anyone else having the same issues and if so, how can I solve this?

        I've set a breakpoint to return a.exec(), but it doesn't go there.

        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
            Login login;
            login.show();
        
            qApp->setQuitOnLastWindowClosed(false);
        
            return a.exec();
        }
        

        could it be the setQuitOnLastWindowClosed(false) that prevents it from closing?
        I need that line to not let my app crash when I show a QMessageBox.

        P Offline
        P Offline
        Pl45m4
        wrote on 8 Nov 2019, 13:45 last edited by Pl45m4 11 Aug 2019, 13:51
        #3

        @hobbyProgrammer

        Do you use a parent-child structure or three independent windows?
        Does your program exits properly, if you close all three windows?
        (If a parent window is still running in the background, your program wont exit)

        EDIT:
        @hobbyProgrammer why you removed the qApp->setQuitOnLastWindowClosed(false) from your post?
        This line is not necessary. If it is in your case, your are doing something else wrong.

        I need that line to not let my app crash when I show a QMessageBox.

        Have a look at your three windows, dialogs and messageBoxes again. Try to figure out, what's going wrong there.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        H 1 Reply Last reply 8 Nov 2019, 13:55
        1
        • P Pl45m4
          8 Nov 2019, 13:45

          @hobbyProgrammer

          Do you use a parent-child structure or three independent windows?
          Does your program exits properly, if you close all three windows?
          (If a parent window is still running in the background, your program wont exit)

          EDIT:
          @hobbyProgrammer why you removed the qApp->setQuitOnLastWindowClosed(false) from your post?
          This line is not necessary. If it is in your case, your are doing something else wrong.

          I need that line to not let my app crash when I show a QMessageBox.

          Have a look at your three windows, dialogs and messageBoxes again. Try to figure out, what's going wrong there.

          H Offline
          H Offline
          hobbyProgrammer
          wrote on 8 Nov 2019, 13:55 last edited by
          #4

          @Pl45m4

          I don't know what I am doing wrong. I followed the examples from the Qt docs.

                  QMessageBox message;                                                                
                  message.setText("QMessageBoxText");
                  message.setStandardButtons(QMessageBox::Yes | QMessageBox::No);                  
          
                  int ret = message.exec();                                                           
          
                  if(ret == QMessageBox::Yes)                                                          
                  {
                      qDebug() << "Yes"
                  }
                  else if(ret == QMessageBox::No)
                  {
                              qDebug() << "No"
                  }
          

          for some reason this closes my entire app, but I can't seem to figure out why.

          J P 2 Replies Last reply 8 Nov 2019, 14:14
          0
          • H hobbyProgrammer
            8 Nov 2019, 13:55

            @Pl45m4

            I don't know what I am doing wrong. I followed the examples from the Qt docs.

                    QMessageBox message;                                                                
                    message.setText("QMessageBoxText");
                    message.setStandardButtons(QMessageBox::Yes | QMessageBox::No);                  
            
                    int ret = message.exec();                                                           
            
                    if(ret == QMessageBox::Yes)                                                          
                    {
                        qDebug() << "Yes"
                    }
                    else if(ret == QMessageBox::No)
                    {
                                qDebug() << "No"
                    }
            

            for some reason this closes my entire app, but I can't seem to figure out why.

            J Offline
            J Offline
            JonB
            wrote on 8 Nov 2019, 14:14 last edited by
            #5

            @hobbyProgrammer
            It will only close your entire app if you have the default setQuitOnLastWindowClosed(true) and this message box is the last window your app has open. You should have another window open if you don't want your app to exit. I don't know why you are hiding windows as you go. I don't know what you expect to happen after you close the last window, if you intend the app to continue you would need another window open for the user to do something in....

            1 Reply Last reply
            3
            • H hobbyProgrammer
              8 Nov 2019, 13:55

              @Pl45m4

              I don't know what I am doing wrong. I followed the examples from the Qt docs.

                      QMessageBox message;                                                                
                      message.setText("QMessageBoxText");
                      message.setStandardButtons(QMessageBox::Yes | QMessageBox::No);                  
              
                      int ret = message.exec();                                                           
              
                      if(ret == QMessageBox::Yes)                                                          
                      {
                          qDebug() << "Yes"
                      }
                      else if(ret == QMessageBox::No)
                      {
                                  qDebug() << "No"
                      }
              

              for some reason this closes my entire app, but I can't seem to figure out why.

              P Offline
              P Offline
              Pl45m4
              wrote on 8 Nov 2019, 14:25 last edited by
              #6

              @hobbyProgrammer

              Normally a MessageBox is shown above some parent Widget like QDialog, QWindow or QMainWindow. If you hide / close all widgets except your MessageBox and close the MessageBox afterwards, your program exits.

              Maybe you can replace your windows with one or two windows with a widget container like QStackedWidget or you replace widgets on runtime. This would reduce the amount of show / hide processes. But depends on you and your needs, what will work best for you. :)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              H 1 Reply Last reply 8 Nov 2019, 14:27
              3
              • P Pl45m4
                8 Nov 2019, 14:25

                @hobbyProgrammer

                Normally a MessageBox is shown above some parent Widget like QDialog, QWindow or QMainWindow. If you hide / close all widgets except your MessageBox and close the MessageBox afterwards, your program exits.

                Maybe you can replace your windows with one or two windows with a widget container like QStackedWidget or you replace widgets on runtime. This would reduce the amount of show / hide processes. But depends on you and your needs, what will work best for you. :)

                H Offline
                H Offline
                hobbyProgrammer
                wrote on 8 Nov 2019, 14:27 last edited by hobbyProgrammer 11 Aug 2019, 14:34
                #7

                @Pl45m4 said in Qt app doesn't close properly (still visible in task manager):

                Maybe you can replace your windows with one or two windows with a widget container like QStackedWidget or you replace widgets on runtime. This would reduce the amount of show / hide processes. But depends on you and your needs, what will work best for you. :)

                That sounds pretty good, but all the windows have different functions. The first window is to login the second is to select something and the third is a drawing app using qgraphicsview.

                P 1 Reply Last reply 8 Nov 2019, 14:34
                0
                • H hobbyProgrammer
                  8 Nov 2019, 14:27

                  @Pl45m4 said in Qt app doesn't close properly (still visible in task manager):

                  Maybe you can replace your windows with one or two windows with a widget container like QStackedWidget or you replace widgets on runtime. This would reduce the amount of show / hide processes. But depends on you and your needs, what will work best for you. :)

                  That sounds pretty good, but all the windows have different functions. The first window is to login the second is to select something and the third is a drawing app using qgraphicsview.

                  P Offline
                  P Offline
                  Pl45m4
                  wrote on 8 Nov 2019, 14:34 last edited by Pl45m4 11 Aug 2019, 14:39
                  #8

                  @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                  replace it with the new window

                  Widget, not window.

                  @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                  So with QStackedWidget I don't need to hide my window

                  Yes, it works like a book. You can dynamically flip pages / widgets instead of showing a new window with static content.

                  @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                  The first window is to login the second is to select something and the third is a drawing app using qgraphicsview

                  I think two windows are enough. You could use a QDialog to login. After successful login, you show your QMainWindow with your QGraphicsView and your "settings". Either at the same time or you put a QStackedWidget on your QMainWindow and flip after you set everything up, to start drawing


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  H 1 Reply Last reply 8 Nov 2019, 14:38
                  0
                  • P Pl45m4
                    8 Nov 2019, 14:34

                    @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                    replace it with the new window

                    Widget, not window.

                    @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                    So with QStackedWidget I don't need to hide my window

                    Yes, it works like a book. You can dynamically flip pages / widgets instead of showing a new window with static content.

                    @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                    The first window is to login the second is to select something and the third is a drawing app using qgraphicsview

                    I think two windows are enough. You could use a QDialog to login. After successful login, you show your QMainWindow with your QGraphicsView and your "settings". Either at the same time or you put a QStackedWidget on your QMainWindow and flip after you set everything up, to start drawing

                    H Offline
                    H Offline
                    hobbyProgrammer
                    wrote on 8 Nov 2019, 14:38 last edited by hobbyProgrammer 11 Aug 2019, 14:39
                    #9

                    @Pl45m4 I understand, but I would (for now) really just like to find a way to make it work with 3 screens. Unless there's an easy way to change the screens to widgets, but I don't have much experience with that.
                    I currently have screens with different UI's.
                    I use screens with menu bars etc. so how can I convert that to a widget?

                    P 1 Reply Last reply 8 Nov 2019, 14:42
                    0
                    • H hobbyProgrammer
                      8 Nov 2019, 14:38

                      @Pl45m4 I understand, but I would (for now) really just like to find a way to make it work with 3 screens. Unless there's an easy way to change the screens to widgets, but I don't have much experience with that.
                      I currently have screens with different UI's.
                      I use screens with menu bars etc. so how can I convert that to a widget?

                      P Offline
                      P Offline
                      Pl45m4
                      wrote on 8 Nov 2019, 14:42 last edited by Pl45m4 11 Aug 2019, 14:44
                      #10

                      @hobbyProgrammer

                      I've edited my last post. Check it out.

                      @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                      I use screens with menu bars etc. so how can I convert that to a widget?

                      You use Menus in your QMainWindow, right? You can leave them as they are.
                      The QStackedWidget would only affect your MainWindows CentralWidget (Content of QMainWindow)

                      QWidget is the base class of nearly everything in Qt. Every widget is... well... a QWidget (or inherits it).

                      See:
                      https://doc.qt.io/qt-5/qwidget.html


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      H 1 Reply Last reply 8 Nov 2019, 14:54
                      1
                      • P Pl45m4
                        8 Nov 2019, 14:42

                        @hobbyProgrammer

                        I've edited my last post. Check it out.

                        @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                        I use screens with menu bars etc. so how can I convert that to a widget?

                        You use Menus in your QMainWindow, right? You can leave them as they are.
                        The QStackedWidget would only affect your MainWindows CentralWidget (Content of QMainWindow)

                        QWidget is the base class of nearly everything in Qt. Every widget is... well... a QWidget (or inherits it).

                        See:
                        https://doc.qt.io/qt-5/qwidget.html

                        H Offline
                        H Offline
                        hobbyProgrammer
                        wrote on 8 Nov 2019, 14:54 last edited by
                        #11

                        @Pl45m4 no the menus are different for each screen. However, I think I can apply this to the first two screens. The third one is diferent...

                        P H 2 Replies Last reply 8 Nov 2019, 15:22
                        0
                        • H hobbyProgrammer
                          8 Nov 2019, 14:54

                          @Pl45m4 no the menus are different for each screen. However, I think I can apply this to the first two screens. The third one is diferent...

                          P Offline
                          P Offline
                          Pl45m4
                          wrote on 8 Nov 2019, 15:22 last edited by
                          #12

                          @hobbyProgrammer

                          I think you are making it more complicated than it really is or I dont understand what you are actually doing / planing to do :)
                          From what I've read the last days, you are coding a more or less "simple" drawing app (with clickable and editable polygons / objects, contextMenu on rightclick and further settings in a different window.... and now with a login window at program start) Correct?


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          H 1 Reply Last reply 11 Nov 2019, 08:14
                          1
                          • P Pl45m4
                            8 Nov 2019, 15:22

                            @hobbyProgrammer

                            I think you are making it more complicated than it really is or I dont understand what you are actually doing / planing to do :)
                            From what I've read the last days, you are coding a more or less "simple" drawing app (with clickable and editable polygons / objects, contextMenu on rightclick and further settings in a different window.... and now with a login window at program start) Correct?

                            H Offline
                            H Offline
                            hobbyProgrammer
                            wrote on 11 Nov 2019, 08:14 last edited by
                            #13

                            @Pl45m4 yes that's correct

                            1 Reply Last reply
                            0
                            • H hobbyProgrammer
                              8 Nov 2019, 14:54

                              @Pl45m4 no the menus are different for each screen. However, I think I can apply this to the first two screens. The third one is diferent...

                              H Offline
                              H Offline
                              hobbyProgrammer
                              wrote on 11 Nov 2019, 10:36 last edited by hobbyProgrammer 11 Nov 2019, 10:36
                              #14

                              @Pl45m4

                              I wouldn't mind it if I had to remake the .ui file, but is there a way to keep the classes as they are?
                              I really don't want 1 big class for this as it would probably be 500 lines of code. I would like it to stay organized.

                              P 1 Reply Last reply 11 Nov 2019, 16:12
                              0
                              • J Offline
                                J Offline
                                JonB
                                wrote on 11 Nov 2019, 11:54 last edited by JonB 11 Nov 2019, 11:56
                                #15

                                @hobbyProgrammer
                                Briefly, because you need this whole behaviour sorted out, as per the mess which is developing in your other thread, https://forum.qt.io/topic/108715/check-button-press-of-qmessagebox.

                                You have two choices:

                                • setQuitOnLastWindowClosed(true): Make sure your code always has a window open, till you/the user chooses to close it and exit the application.

                                • setQuitOnLastWindowClosed(false): If you cannot do the above, you must recognise in code when the last of your windows is closed and then exit the application explicitly.

                                1 Reply Last reply
                                0
                                • H hobbyProgrammer
                                  11 Nov 2019, 10:36

                                  @Pl45m4

                                  I wouldn't mind it if I had to remake the .ui file, but is there a way to keep the classes as they are?
                                  I really don't want 1 big class for this as it would probably be 500 lines of code. I would like it to stay organized.

                                  P Offline
                                  P Offline
                                  Pl45m4
                                  wrote on 11 Nov 2019, 16:12 last edited by Pl45m4 11 Nov 2019, 16:13
                                  #16

                                  @hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):

                                  I really don't want 1 big class for this as it would probably be 500 lines of code

                                  500 LOC are not that much actually :)

                                  You need to know what you want. If you set setQuitOnLastWindowClosed(false) only because of your MessageBox behavior, there is something wrong / not well structured with your classes.


                                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                  ~E. W. Dijkstra

                                  1 Reply Last reply
                                  1

                                  1/16

                                  8 Nov 2019, 13:10

                                  • Login

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