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. How to catch segmentation fault.
Forum Updated to NodeBB v4.3 + New Features

How to catch segmentation fault.

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 5.9k Views
  • 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.
  • Q Offline
    Q Offline
    Qingshui Kong
    wrote on 29 Aug 2019, 07:43 last edited by Qingshui Kong
    #1

    Hello everybody,
    Could anybody help me?
    Recently I am learning QT. But segmentation fault often happens. I know it's critial. But I still hope the application can continue when the error happens. I find a open source library on the Internet. It is 'segvcatch'. It works.
    But unfortunately, it is said not safe. What's more, if segmentation fault happens in some sub thread, the application still crashes. That means it doesn't work for multi-thread.
    So what should I do? Is there any solution for QT?
    I work on Ubtuntu 16.04, and I use QT 5.9.1.
    Could somebody give me any advice? Thanks in advance.

    A 1 Reply Last reply 29 Aug 2019, 07:49
    0
    • Q Qingshui Kong
      29 Aug 2019, 07:43

      Hello everybody,
      Could anybody help me?
      Recently I am learning QT. But segmentation fault often happens. I know it's critial. But I still hope the application can continue when the error happens. I find a open source library on the Internet. It is 'segvcatch'. It works.
      But unfortunately, it is said not safe. What's more, if segmentation fault happens in some sub thread, the application still crashes. That means it doesn't work for multi-thread.
      So what should I do? Is there any solution for QT?
      I work on Ubtuntu 16.04, and I use QT 5.9.1.
      Could somebody give me any advice? Thanks in advance.

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 29 Aug 2019, 07:49 last edited by
      #2

      @qingshui-kong said in How to catch segmentation fault.:

      But I still hope the application can continue when the error happens.

      No. Segmentation faults are programming errors, no continuation expected.

      Fix you errors and your program will run without SEGFAULTs

      Regards

      Qt has to stay free or it will die.

      Q 1 Reply Last reply 29 Aug 2019, 07:54
      5
      • A aha_1980
        29 Aug 2019, 07:49

        @qingshui-kong said in How to catch segmentation fault.:

        But I still hope the application can continue when the error happens.

        No. Segmentation faults are programming errors, no continuation expected.

        Fix you errors and your program will run without SEGFAULTs

        Regards

        Q Offline
        Q Offline
        Qingshui Kong
        wrote on 29 Aug 2019, 07:54 last edited by
        #3

        @aha_1980
        Thanks.
        Yes, no contiuation is expected.
        But could we do that as segvcatch did?
        The reason is that I want to pop some message box to tell me what happens. If not, I am confused. 'What happened?' and 'Why did the application exit?'

        J 1 Reply Last reply 29 Aug 2019, 07:56
        0
        • Q Qingshui Kong
          29 Aug 2019, 07:54

          @aha_1980
          Thanks.
          Yes, no contiuation is expected.
          But could we do that as segvcatch did?
          The reason is that I want to pop some message box to tell me what happens. If not, I am confused. 'What happened?' and 'Why did the application exit?'

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 29 Aug 2019, 07:56 last edited by
          #4

          @qingshui-kong said in How to catch segmentation fault.:

          If not, I am confused. 'What happened?' and 'Why did the application exit?

          That's what the debugger is for


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          Q 1 Reply Last reply 29 Aug 2019, 08:07
          4
          • J J.Hilk
            29 Aug 2019, 07:56

            @qingshui-kong said in How to catch segmentation fault.:

            If not, I am confused. 'What happened?' and 'Why did the application exit?

            That's what the debugger is for

            Q Offline
            Q Offline
            Qingshui Kong
            wrote on 29 Aug 2019, 08:07 last edited by
            #5

            @j-hilk
            Thanks.
            Yes, I should debug to find out the fault.
            But if the fault didn't happen before the aaplication was released. Then I released it. It happened when someone using it. The user didn't know what happened. He just thought it was a bad application and didn't want to use it any more. I don't think that is what we want.

            J C 2 Replies Last reply 29 Aug 2019, 08:12
            0
            • Q Qingshui Kong
              29 Aug 2019, 08:07

              @j-hilk
              Thanks.
              Yes, I should debug to find out the fault.
              But if the fault didn't happen before the aaplication was released. Then I released it. It happened when someone using it. The user didn't know what happened. He just thought it was a bad application and didn't want to use it any more. I don't think that is what we want.

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 29 Aug 2019, 08:12 last edited by
              #6

              @qingshui-kong
              https://forum.qt.io/topic/106321/how-to-compile-with-debug-symbol/8


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              Q 1 Reply Last reply 29 Aug 2019, 08:18
              0
              • J J.Hilk
                29 Aug 2019, 08:12

                @qingshui-kong
                https://forum.qt.io/topic/106321/how-to-compile-with-debug-symbol/8

                Q Offline
                Q Offline
                Qingshui Kong
                wrote on 29 Aug 2019, 08:18 last edited by
                #7

                @j-hilk
                Yeah, that is posted by me. That is how to debug.
                But I just think it is not very good if the application crashes directly when some error occurs.
                If there is no solution, maybe I should give up.

                J 1 Reply Last reply 29 Aug 2019, 08:33
                -1
                • Q Qingshui Kong
                  29 Aug 2019, 08:18

                  @j-hilk
                  Yeah, that is posted by me. That is how to debug.
                  But I just think it is not very good if the application crashes directly when some error occurs.
                  If there is no solution, maybe I should give up.

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 29 Aug 2019, 08:33 last edited by
                  #8

                  @qingshui-kong
                  you could try Python or Rust, you will be hard pressed to run into memory error issues with those languages.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • Q Qingshui Kong
                    29 Aug 2019, 08:07

                    @j-hilk
                    Thanks.
                    Yes, I should debug to find out the fault.
                    But if the fault didn't happen before the aaplication was released. Then I released it. It happened when someone using it. The user didn't know what happened. He just thought it was a bad application and didn't want to use it any more. I don't think that is what we want.

                    C Offline
                    C Offline
                    Cobra91151
                    wrote on 29 Aug 2019, 08:36 last edited by Cobra91151
                    #9

                    @qingshui-kong

                    Hello!

                    The segmentation fault must be fixed sooner or later! But in case you want to store the crash logging information.

                    Code:

                    #include <signal.h>
                    
                    void manageSegFailure(int signalCode);
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication app(argc, argv);
                        signal(SIGSEGV, manageSegFailure);
                        ....
                    }
                    
                    void manageSegFailure(int signalCode)
                    {
                        int userResult = QMessageBox::critical(nullptr, "Error", "Unexpected error has occurred! Do you want to submit the feedback?", QMessageBox::Yes | QMessageBox::No);
                    
                        if (userResult == QMessageBox::Yes) {
                            // You can store the logging info here.
                        }
                    
                        signal(signalCode, SIG_DFL);
                        QApplication::exit(3);
                    }
                    

                    The application will still crash, but before it will display the msgbox. Also, my code works on Windows, I am not sure about Ubuntu, you have to check it there. Happy coding!

                    Q 1 Reply Last reply 29 Aug 2019, 08:40
                    3
                    • C Cobra91151
                      29 Aug 2019, 08:36

                      @qingshui-kong

                      Hello!

                      The segmentation fault must be fixed sooner or later! But in case you want to store the crash logging information.

                      Code:

                      #include <signal.h>
                      
                      void manageSegFailure(int signalCode);
                      
                      int main(int argc, char *argv[])
                      {
                          QApplication app(argc, argv);
                          signal(SIGSEGV, manageSegFailure);
                          ....
                      }
                      
                      void manageSegFailure(int signalCode)
                      {
                          int userResult = QMessageBox::critical(nullptr, "Error", "Unexpected error has occurred! Do you want to submit the feedback?", QMessageBox::Yes | QMessageBox::No);
                      
                          if (userResult == QMessageBox::Yes) {
                              // You can store the logging info here.
                          }
                      
                          signal(signalCode, SIG_DFL);
                          QApplication::exit(3);
                      }
                      

                      The application will still crash, but before it will display the msgbox. Also, my code works on Windows, I am not sure about Ubuntu, you have to check it there. Happy coding!

                      Q Offline
                      Q Offline
                      Qingshui Kong
                      wrote on 29 Aug 2019, 08:40 last edited by
                      #10

                      @cobra91151
                      OK. Thank you very much.
                      Yes, I tried this solution before.

                      1 Reply Last reply
                      0

                      1/10

                      29 Aug 2019, 07:43

                      • Login

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