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.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); }
-
Hi,
Since you are running a QApplication, you should rather use the exit method from it. i.e. replace
exit(0)
byqApp->exit(0)
-
@SGaist's advice should fix your crash.
For an exit(0) I use
qApp->quit()
, butqApp->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.
-
Hi,
Since you are running a QApplication, you should rather use the exit method from it. i.e. replace
exit(0)
byqApp->exit(0)
@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).
-
@SGaist's advice should fix your crash.
For an exit(0) I use
qApp->quit()
, butqApp->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.
@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??
-
@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??