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

    aha_1980A 1 Reply Last reply
    0
    • Q Qingshui Kong

      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.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 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
      5
      • aha_1980A aha_1980

        @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 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.HilkJ 1 Reply Last reply
        0
        • Q Qingshui Kong

          @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.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on 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
          4
          • J.HilkJ J.Hilk

            @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 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.HilkJ Cobra91151C 2 Replies Last reply
            0
            • Q Qingshui Kong

              @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.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on 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
              0
              • J.HilkJ J.Hilk

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

                Q Offline
                Q Offline
                Qingshui Kong
                wrote on 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.HilkJ 1 Reply Last reply
                -1
                • Q Qingshui Kong

                  @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.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on 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

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

                    Cobra91151C Offline
                    Cobra91151C Offline
                    Cobra91151
                    wrote on 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
                    3
                    • Cobra91151C Cobra91151

                      @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 last edited by
                      #10

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

                      1 Reply Last reply
                      0

                      • Login

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