Qt World Summit: Submit your Presentation

Getting "Segmentation fault (core dumped)" while doing "Exit(0)" after message_box.exec()

  • Hi all,
    Actually i'm getting "Segmentation fault (core dumped)" when i do "exit(0)" just after message_box.exec(). is i'm missing some thing or going in a wrong way please lemme know what is going on. here is my code attached below.


    #include "mainwindow.h"
    #include <QApplication>
    #include "eula.h"
    #include <iostream>
    #include <sstream>
    #include "util.h"
    using namespace std;
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        Eula e ;
        bool b;
        acceptanceCheck ac;
            MainWindow* w = new MainWindow ;
        return a.exec();

    exit code in a different file

                     QMessageBox msgBox2;
                     msgBox2.setText("'memap' size is not in G/M/K in grub");
                     msgBox2.setStandardButtons(QMessageBox::Ok );
                     int ret = msgBox2.exec();
         //            if (ret == QMessageBox::Ok)
         //                msgBox2.close();
        //             QMessageBox::warning(NULL,"Grub Error","'memap' size is not in G/M/K in grub");

  • Lifetime Qt Champion


    Since you are running a QApplication, you should rather use the exit method from it. i.e. replace exit(0) by qApp->exit(0)

  • @SGaist's advice should fix your crash.

    For an exit(0) I use qApp->quit(), but qApp->exit(0) should be fine.

    If you are still crashing throw it in a debugger and show us the backtrace. My guess is you still have things on the event loop that can't be handled because exit(0) forces the event loop closed without allowing it process it's closure events.

  • @SGaist, thanks for reply.

    i tried all but still getting the same "Segmentation fault (core dumped)". And one more thing is i'm not getting this every time but rarely and surprisingly (like sometimes after 4/5 trials or even more trials and sometimes after 2/3 trails like that).

  • @ambershark thanks for reply,

    if i'm not using message_box then i'm not facing any issue. it seems this issue is relevant to messag_box, isn't??

  • Lifetime Qt Champion

    @moyin You should run your app through debugger and when it crashes check the stack trace

Log in to reply