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. quit Qt application, not working
Forum Updated to NodeBB v4.3 + New Features

quit Qt application, not working

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 5 Posters 21.5k Views 3 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #3

    Hi
    check the return from connect to see if its ok.
    You tell is that "this" have a function quit()
    is that true?
    Maybe this should be application?

    Did you try just to call close() ?

    edit: @JKSH was faster :)

    O 1 Reply Last reply
    3
    • mrjjM mrjj

      Hi
      check the return from connect to see if its ok.
      You tell is that "this" have a function quit()
      is that true?
      Maybe this should be application?

      Did you try just to call close() ?

      edit: @JKSH was faster :)

      O Offline
      O Offline
      o6a6r9v1p
      wrote on last edited by
      #4

      @mrjj

      Inside user class, a push button is created to close the program itself, when necessary.
      The statement is used in a function that belongs to the user class.

      i tried close() also, but the program is not closing.

      mrjjM 1 Reply Last reply
      0
      • O o6a6r9v1p

        @mrjj

        Inside user class, a push button is created to close the program itself, when necessary.
        The statement is used in a function that belongs to the user class.

        i tried close() also, but the program is not closing.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #5

        @o6a6r9v1p
        Ok but the user class should then connect to Application instance
        so it would be
        qDebug() << "quit conn:" << connect(ui->pushButton, SIGNAL(clicked()), qApp, SLOT(quit()));

        and check it says
        quit conn: true

        O 1 Reply Last reply
        1
        • mrjjM mrjj

          @o6a6r9v1p
          Ok but the user class should then connect to Application instance
          so it would be
          qDebug() << "quit conn:" << connect(ui->pushButton, SIGNAL(clicked()), qApp, SLOT(quit()));

          and check it says
          quit conn: true

          O Offline
          O Offline
          o6a6r9v1p
          wrote on last edited by
          #6

          @mrjj
          thanks for the help. But it didnot work.
          Compiler gives the error:
          ui was not declared in this scope.

          mrjjM 1 Reply Last reply
          0
          • O o6a6r9v1p

            @mrjj
            thanks for the help. But it didnot work.
            Compiler gives the error:
            ui was not declared in this scope.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #7

            @o6a6r9v1p

            just use
            hCloseButton
            instead :)
            the ui->butt was just from my sample to see that it did close.

            You did read docs about connect ?
            http://doc.qt.io/qt-5/signalsandslots.html

            This is a MUST read if you are to use Qt.

            1 Reply Last reply
            4
            • O Offline
              O Offline
              o6a6r9v1p
              wrote on last edited by
              #8

              I have this main function
              @int main (int argc, char* argv[])
              {

              QApplication app(argc, argv);
              

              // setLayout(verticalLayout);
              // window.setWindowTitle(QApplication::translate("Device Monitor"));

              myApp w;
              

              // w.show();

              return app.exec();
              

              }
              @

              myApp is user class, in this "CLOSE" button is created. we want to use it , instead of using "X" in GUI to close the application.
              we didnot use QT creator to generate GUI, we wrote it.

              this is where difference comes between my code and examples & ideas given in the forum.

              jsulmJ 1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #9

                Hi
                Actually the X close the window
                QApplication is set to exit exec()
                when last top window is closed

                It dont matter if u used UI file or programmed it.

                But the shown connect
                qDebug() << "quit conn:" << connect(ui->pushButton, SIGNAL(clicked()), qApp, SLOT(quit()));

                will not close window but try to make whole app quit.

                O 1 Reply Last reply
                1
                • O o6a6r9v1p

                  I have this main function
                  @int main (int argc, char* argv[])
                  {

                  QApplication app(argc, argv);
                  

                  // setLayout(verticalLayout);
                  // window.setWindowTitle(QApplication::translate("Device Monitor"));

                  myApp w;
                  

                  // w.show();

                  return app.exec();
                  

                  }
                  @

                  myApp is user class, in this "CLOSE" button is created. we want to use it , instead of using "X" in GUI to close the application.
                  we didnot use QT creator to generate GUI, we wrote it.

                  this is where difference comes between my code and examples & ideas given in the forum.

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

                  @o6a6r9v1p See http://doc.qt.io/qt-5.8/qwidget.html#closeEvent

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

                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Hi
                    Actually the X close the window
                    QApplication is set to exit exec()
                    when last top window is closed

                    It dont matter if u used UI file or programmed it.

                    But the shown connect
                    qDebug() << "quit conn:" << connect(ui->pushButton, SIGNAL(clicked()), qApp, SLOT(quit()));

                    will not close window but try to make whole app quit.

                    O Offline
                    O Offline
                    o6a6r9v1p
                    wrote on last edited by
                    #11

                    @mrjj
                    i did as you told, I got the following

                    1. when i used
                      @
                      connect(hCloseButton, SIGNAL(clicked()), this, SLOT(quit()));
                      @

                    it gave the message
                    "QObject::connect: No such slot myApp::quit()"

                    it compiles with no errors.
                    When Pushbutton is pressed it does not close the Application.

                    1. when i used
                      @
                      connect(hCloseButton, SIGNAL(clicked()), qApp, SLOT(quit()));
                      @
                      it did not compile.
                      it gave the error message
                      "qApp was not declared in this scope"
                    J.HilkJ 1 Reply Last reply
                    0
                    • O o6a6r9v1p

                      @mrjj
                      i did as you told, I got the following

                      1. when i used
                        @
                        connect(hCloseButton, SIGNAL(clicked()), this, SLOT(quit()));
                        @

                      it gave the message
                      "QObject::connect: No such slot myApp::quit()"

                      it compiles with no errors.
                      When Pushbutton is pressed it does not close the Application.

                      1. when i used
                        @
                        connect(hCloseButton, SIGNAL(clicked()), qApp, SLOT(quit()));
                        @
                        it did not compile.
                        it gave the error message
                        "qApp was not declared in this scope"
                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #12

                      @o6a6r9v1p

                      qApp is a global pointer referring to the unique application object. It is equivalent to QCoreApplication::instance(), but cast as a QApplication pointer, so only valid when the unique application object is a QApplication.

                      -> your main does not have a QApplication object

                      You said, you have no UI for the designer so I Asume you have a QCoreApplication in your main.

                      and try the following in it

                      //create a `myApp::quit()`
                      QCoreApplication::quit();
                      

                      or

                      connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
                      

                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      mrjjM 1 Reply Last reply
                      2
                      • J.HilkJ J.Hilk

                        @o6a6r9v1p

                        qApp is a global pointer referring to the unique application object. It is equivalent to QCoreApplication::instance(), but cast as a QApplication pointer, so only valid when the unique application object is a QApplication.

                        -> your main does not have a QApplication object

                        You said, you have no UI for the designer so I Asume you have a QCoreApplication in your main.

                        and try the following in it

                        //create a `myApp::quit()`
                        QCoreApplication::quit();
                        

                        or

                        connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
                        
                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        Hi
                        just include
                        #include <QApplication>
                        and its known.

                        Or as @J-Hilk says if that is the case :)

                        O 1 Reply Last reply
                        2
                        • mrjjM mrjj

                          Hi
                          just include
                          #include <QApplication>
                          and its known.

                          Or as @J-Hilk says if that is the case :)

                          O Offline
                          O Offline
                          o6a6r9v1p
                          wrote on last edited by
                          #14

                          @mrjj
                          Thanks for your help.
                          I included <QApplication>
                          and
                          connect(hCloseButton, SIGNAL(clicked()), qApp, SLOT(quit()));
                          worked fine now.

                          "myApp" gui is closing now.

                          1 Reply Last reply
                          1

                          • Login

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