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 an application without crashing it... instance().show()

How to exit an application without crashing it... instance().show()

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 7.3k Views
  • 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.
  • T Offline
    T Offline
    TheCrowKaka
    wrote on last edited by
    #1

    Hello
    This is an application for Android.
    I am starting a simple mainwindow application in this way as shown here.

        MainWindow::instance().show();
        return a.exec();
    

    If I use

        QCoreApplication::exit(0);
    OR
        QApplication::quit();
    

    to quit the application, The application crashes and I get a message as here.

    F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 5818 (QtThread)
    

    What is the right way to quit the application when using instance().show();

    I am required to use the instance with the mainwindow in order to receive data from java classes, following the kdab example 7 here.

    Thanks.

    A Qt Enthusiastic...

    J.HilkJ 1 Reply Last reply
    0
    • T TheCrowKaka

      Hello
      This is an application for Android.
      I am starting a simple mainwindow application in this way as shown here.

          MainWindow::instance().show();
          return a.exec();
      

      If I use

          QCoreApplication::exit(0);
      OR
          QApplication::quit();
      

      to quit the application, The application crashes and I get a message as here.

      F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 5818 (QtThread)
      

      What is the right way to quit the application when using instance().show();

      I am required to use the instance with the mainwindow in order to receive data from java classes, following the kdab example 7 here.

      Thanks.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @TheCrowKaka

      the right way to close an application is, like you did, to call quit:

      Docu-quote:

      void QCoreApplication::quit()
      
      Tells the application to exit with return code 0 (success). Equivalent to calling QCoreApplication::exit(0).
      
      It's common to connect the QGuiApplication::lastWindowClosed() signal to quit(), and you also often connect e.g. QAbstractButton::clicked() or signals in QAction, QMenu, or QMenuBar to it.
      
      [Example:](http://doc.qt.io/qt-5/qcoreapplication.html#quit)
      
      QPushButton *quitButton = new QPushButton("Quit");
      connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
      See also exit(), aboutToQuit(), and QGuiApplication::lastWindowClosed().
      

      seems like one ore more of your classes/instances do not quit properly


      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.

      T 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @TheCrowKaka

        the right way to close an application is, like you did, to call quit:

        Docu-quote:

        void QCoreApplication::quit()
        
        Tells the application to exit with return code 0 (success). Equivalent to calling QCoreApplication::exit(0).
        
        It's common to connect the QGuiApplication::lastWindowClosed() signal to quit(), and you also often connect e.g. QAbstractButton::clicked() or signals in QAction, QMenu, or QMenuBar to it.
        
        [Example:](http://doc.qt.io/qt-5/qcoreapplication.html#quit)
        
        QPushButton *quitButton = new QPushButton("Quit");
        connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
        See also exit(), aboutToQuit(), and QGuiApplication::lastWindowClosed().
        

        seems like one ore more of your classes/instances do not quit properly

        T Offline
        T Offline
        TheCrowKaka
        wrote on last edited by
        #3

        @J.Hilk
        Yes, even i guess the same.
        When i start the application like

        Mainwindow w;
        w.show();
        

        There is no crashing when i quit the application.

        How to close the instance() before quitting the main application.

        Thanks.

        A Qt Enthusiastic...

        jsulmJ 1 Reply Last reply
        0
        • T TheCrowKaka

          @J.Hilk
          Yes, even i guess the same.
          When i start the application like

          Mainwindow w;
          w.show();
          

          There is no crashing when i quit the application.

          How to close the instance() before quitting the main application.

          Thanks.

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

          @TheCrowKaka Is your MainWindow a singleton? If yes why? What's the point to implement it as a singleton?

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

          T 1 Reply Last reply
          0
          • jsulmJ jsulm

            @TheCrowKaka Is your MainWindow a singleton? If yes why? What's the point to implement it as a singleton?

            T Offline
            T Offline
            TheCrowKaka
            wrote on last edited by
            #5

            @jsulm
            As I mentioned earlier, I am required to call some java classes and get values from those classes.
            I am not so good as far as multithreading applications are concerned as well as not at all expert at interacting with java classes.

            I just followed the kdab example on how to implement the java classes. You can find the link to the post in my first post.. here.

            Now the interface with java classes works great but this fatal signal problem is seen.
            So I though maybe there is a different way to exit the application when using instance().show() method.

            Thanks.

            A Qt Enthusiastic...

            jsulmJ 1 Reply Last reply
            0
            • T TheCrowKaka

              @jsulm
              As I mentioned earlier, I am required to call some java classes and get values from those classes.
              I am not so good as far as multithreading applications are concerned as well as not at all expert at interacting with java classes.

              I just followed the kdab example on how to implement the java classes. You can find the link to the post in my first post.. here.

              Now the interface with java classes works great but this fatal signal problem is seen.
              So I though maybe there is a different way to exit the application when using instance().show() method.

              Thanks.

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

              @TheCrowKaka The right way to exit the app is QCoreApplication::quit() as @J-Hilk already said.
              If your app is crashing on exit then you have a bug somewhere. You need to debug or at least posthere whole stack trace when it is crashing.

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

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TheCrowKaka
                wrote on last edited by
                #7

                Thanks everyone for your time to reply to this post.

                I finally managed to solve it.
                I was declaring the instance slot such that it returned a reference rather than a pointer. This is a way that it blocked deleting of that object and which is what was crashing the application when it tried to quit.

                I changed the way of declaring the singleton and it solved the problem.
                This small tutorial helped me understand this.
                http://www.bogotobogo.com/DesignPatterns/singleton.php

                Thanks.

                A Qt Enthusiastic...

                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