Important: Please read the Qt Code of Conduct -

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

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

        return a.exec();

    If I use


    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.


  • Moderators


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


    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.
    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

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

    Mainwindow w;;

    There is no crashing when i quit the application.

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


  • Qt Champions 2019

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

  • @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.


  • Qt Champions 2019

    @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.

  • 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.


Log in to reply