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. [SOLVED] The program has unexpectedly finished
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] The program has unexpectedly finished

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.3k Views 1 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.
  • S Offline
    S Offline
    sftpck
    wrote on 16 Jun 2014, 15:30 last edited by
    #1

    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&#40;&#41;;
    

    }
    @

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arsinte_andrei
      wrote on 16 Jun 2014, 16:25 last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sftpck
        wrote on 16 Jun 2014, 17:01 last edited by
        #3

        Thank you for your reply arsinte_andrei.

        I added the code you posted, but it is never called when the application crash.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sftpck
          wrote on 16 Jun 2014, 17:33 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sftpck
            wrote on 17 Jun 2014, 09:11 last edited by
            #5

            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.

            1 Reply Last reply
            0

            1/5

            16 Jun 2014, 15:30

            • Login

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