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. this->close is not working correctly
Qt 6.11 is out! See what's new in the release blog

this->close is not working correctly

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 5 Posters 5.9k 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.
  • U UG SEP

    Here is the Main Window @jsulm

    ui->setupUi(this);
        this->hide();
        Login log;
        log.setModal(true);
        log.exec();
        this->show();
    

    And well I did think that the program crashed because the application output show that the program exited with code(0) means runs successfully

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #6

    @UG-SEP How does it behave if you do not hide the main window?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    Christian EhrlicherC U 2 Replies Last reply
    0
    • jsulmJ jsulm

      @UG-SEP How does it behave if you do not hide the main window?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #7

      @jsulm said in this->close is not working correctly:

      How does it behave if you do not hide the main window?

      The all works as expected:

      https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      jsulmJ 1 Reply Last reply
      2
      • jsulmJ jsulm

        @UG-SEP How does it behave if you do not hide the main window?

        U Offline
        U Offline
        UG SEP
        wrote on last edited by UG SEP
        #8

        @jsulm then also it closes both windows
        as well as I have checked whether after this->close run does the controller comes to main window or not by checking it using qDebug()<<

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @jsulm said in this->close is not working correctly:

          How does it behave if you do not hide the main window?

          The all works as expected:

          https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #9

          @Christian-Ehrlicher The main window was not closed, just hidden.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          U 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Christian-Ehrlicher The main window was not closed, just hidden.

            U Offline
            U Offline
            UG SEP
            wrote on last edited by
            #10

            @jsulm It is closed because the Application Output give the output:

            13:41:39: E:\Qt in c++\Projects in Qt\build-BlackJack-Desktop_Qt_6_0_4_MinGW_64_bit-Debug\debug\BlackJack.exe exited with code 0
            
            
            jsulmJ 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #11

              Hi,

              If you only have one top level widget visible and close it, then the application will stop. As @Christian-Ehrlicher already pointed out, it's the normal behaviour.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • U UG SEP

                @jsulm It is closed because the Application Output give the output:

                13:41:39: E:\Qt in c++\Projects in Qt\build-BlackJack-Desktop_Qt_6_0_4_MinGW_64_bit-Debug\debug\BlackJack.exe exited with code 0
                
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #12

                @UG-SEP Yes, see the link @Christian-Ehrlicher posted, especially this part: "If this property is true, the applications quits when the last visible primary window". So, is this property set to true?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                Christian EhrlicherC 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @UG-SEP Yes, see the link @Christian-Ehrlicher posted, especially this part: "If this property is true, the applications quits when the last visible primary window". So, is this property set to true?

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  @jsulm said in this->close is not working correctly:

                  So, is this property set to true?

                  Yes since it was not set to false :)

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  jsulmJ 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @jsulm said in this->close is not working correctly:

                    So, is this property set to true?

                    Yes since it was not set to false :)

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    @Christian-Ehrlicher said in this->close is not working correctly:

                    Yes since it was not set to false :)

                    How do you know? :-)

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @Christian-Ehrlicher said in this->close is not working correctly:

                      Yes since it was not set to false :)

                      How do you know? :-)

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #15

                      @jsulm said in this->close is not working correctly:

                      How do you know? :-)

                      Since the default is true and I'm pretty sure it's not modified here.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      0
                      • U Offline
                        U Offline
                        UG SEP
                        wrote on last edited by UG SEP
                        #16

                        @jsulm, @Christian-Ehrlicher, @SGaist

                         ui->setupUi(this);
                            QGuiApplication::setQuitOnLastWindowClosed(false);
                            Login log;
                            log.setModal(true);
                            log.exec();
                        

                        I set it false but then also it the behaviour didn't changed

                        Pl45m4P 1 Reply Last reply
                        0
                        • U UG SEP

                          @jsulm, @Christian-Ehrlicher, @SGaist

                           ui->setupUi(this);
                              QGuiApplication::setQuitOnLastWindowClosed(false);
                              Login log;
                              log.setModal(true);
                              log.exec();
                          

                          I set it false but then also it the behaviour didn't changed

                          Pl45m4P Offline
                          Pl45m4P Offline
                          Pl45m4
                          wrote on last edited by
                          #17

                          @UG-SEP

                          Are your this window and the other window in a parent / child relation? If you close the parent, the child window may also get closed together with it.


                          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
                          0
                          • Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #18

                            As it seems this second dialog is opened in the ctor of the first... strange idea. How should this work at all?
                            Move it out of the ctor, check the return value and oen (or not) the mainwindow afterwards.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            U 1 Reply Last reply
                            4
                            • Christian EhrlicherC Christian Ehrlicher

                              As it seems this second dialog is opened in the ctor of the first... strange idea. How should this work at all?
                              Move it out of the ctor, check the return value and oen (or not) the mainwindow afterwards.

                              U Offline
                              U Offline
                              UG SEP
                              wrote on last edited by
                              #19

                              @Christian-Ehrlicher ok as I will do it right now but can you tell me that how can I convert the base main window.CPP as child and Second Window as parent

                              Pl45m4P 1 Reply Last reply
                              0
                              • U UG SEP

                                @Christian-Ehrlicher ok as I will do it right now but can you tell me that how can I convert the base main window.CPP as child and Second Window as parent

                                Pl45m4P Offline
                                Pl45m4P Offline
                                Pl45m4
                                wrote on last edited by Pl45m4
                                #20

                                @UG-SEP

                                You dont need to "convert" anything. QMainWindow is just a regular QWidget, extended with QToolBars and other stuff.
                                So you can pass a parent QWidget to the c'tor.

                                For example you could create both widgets in your main.cpp, pass the parent with the MainWindow c'tor and show the Login form.

                                • https://doc.qt.io/qt-5/qmainwindow.html#QMainWindow

                                Edit:
                                I'm assuming you what to do something like this, since your 2nd widget is called Login.:

                                • https://stackoverflow.com/questions/24520430/qt-login-dialog-box-before-main-window

                                There are so many examples out there...
                                (If you do it like this, they both can be independent widgets. Then you dont even need a parent / child relation. It's all about a good design / structure.)


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

                                ~E. W. Dijkstra

                                U 1 Reply Last reply
                                1
                                • Pl45m4P Pl45m4

                                  @UG-SEP

                                  You dont need to "convert" anything. QMainWindow is just a regular QWidget, extended with QToolBars and other stuff.
                                  So you can pass a parent QWidget to the c'tor.

                                  For example you could create both widgets in your main.cpp, pass the parent with the MainWindow c'tor and show the Login form.

                                  • https://doc.qt.io/qt-5/qmainwindow.html#QMainWindow

                                  Edit:
                                  I'm assuming you what to do something like this, since your 2nd widget is called Login.:

                                  • https://stackoverflow.com/questions/24520430/qt-login-dialog-box-before-main-window

                                  There are so many examples out there...
                                  (If you do it like this, they both can be independent widgets. Then you dont even need a parent / child relation. It's all about a good design / structure.)

                                  U Offline
                                  U Offline
                                  UG SEP
                                  wrote on last edited by UG SEP
                                  #21

                                  @Pl45m4, @jsulm, @Christian-Ehrlicher, @SGaist thanks a lot bro
                                  As I ask questions here I get a large variety which makes me much mature in qt
                                  Thanks from the bottom of my heart...

                                  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