[SOLVED] The program has unexpectedly finished
-
Hello.
I created a new application project (qt widgets) and add 2 lines of code after QApplication a(argc, argv);:@
QMessageBox::critical(NULL, "test", "test");
exit(0);
@Program compiles and runs. But sometimes QT creator shows "The program has unexpectedly finished" and that the executable has crashed. It is random and happens on debug/release with gcc and llvm/clang. Kubuntu 64bits machine with QT 5.3.
@
#include "mainwindow.h"
#include <QApplication>
#include <QMessageBox>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QMessageBox::critical(NULL, "test", "test"); exit(0); MainWindow w; w.show(); return a.exec();
}
@I found this site: http://blogs.kde.org/node/3919 about how to crash (almost) every Qt/KDE, but it didn't help much.
Any help is appreciated.
Thank you. -
can you add on your main
@void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg){
QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
abort();
}
}int main(int argc, char *argv[]){
qInstallMessageHandler(myMessageOutput);
QApplication app(argc, argv);
........................ and yu other lines
@
now maybe you can trace your program also use debug mode any error like c passing arg? or something similar?? -
Thank you for your reply arsinte_andrei.
I added the code you posted, but it is never called when the application crash.
-
Just tested with a Windows machine (Windows Vista 64bits) without any problems.
Also tested with a Ubuntu machine and got the same "The program has unexpectedly finished” problem. -
Changed line:
@
exit(0);
@to:
@
return 0;
@And no more “The program has unexpectedly finished” crash.
According to "stackoverflow":http://stackoverflow.com/questions/461449/return-statement-vs-exit-in-main
bq. When I call return in main(), destructors will be called for my locally scoped objects. If I call exit(), no destructor will be called for my locally scoped objects!bq.