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. Getting "Segmentation fault (core dumped)" while doing "Exit(0)" after message_box.exec()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.3k 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.
  • M Offline
    M Offline
    moyin
    wrote on last edited by
    #1

    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.

    Main.cpp

    #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);
        HelpFun(argc,argv);
    
    
        Eula e ;
        bool b;
        acceptanceCheck ac;
        b=ac.createFileIfNotexist();
    
        if(b==true)
        {
            e.show();
        }
        else
        {
            MainWindow* w = new MainWindow ;
            w->showMaximized();
        }
    
        return a.exec();
    }
    

    exit code in a different file

    {
                     QMessageBox msgBox2;
                     msgBox2.setWindowTitle("Warning");
                     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");
    
                     exit(0);
                 }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

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

      M 1 Reply Last reply
      3
      • A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

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

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        M 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

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

          M Offline
          M Offline
          moyin
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • A ambershark

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

            M Offline
            M Offline
            moyin
            wrote on last edited by
            #5

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

            jsulmJ 1 Reply Last reply
            0
            • M moyin

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

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

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

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

              1 Reply Last reply
              2

              • Login

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