Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to open stack trace in QT?
Forum Updated to NodeBB v4.3 + New Features

How to open stack trace in QT?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
14 Posts 4 Posters 4.2k 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.
  • P Offline
    P Offline
    PikaCat
    wrote on last edited by
    #1
    #include<bits/stdc++.h>
    void badFunction(){
        throw std::out_of_range("");
    }
    int main(){
        badFunction();
        return 0;
    }
    

    Just like the code above. When I use debug mode to run the code, it will terminate immediately and leave only a message of terminate called after throwing out_of_range.

    Imagine this is a big project with hundreds and thousands of functions in it. When it throws an exception like this, I don't know where the exception occurred.

    In Visual Studio, it will tell you that the unhandled exception in which file, which function and which line, and when you look at that line, there is a big red cross after that code, so I can handle that easily.

    However, in Qt, I have to make a breakpoint at the beginning of the main function and trace down the code line by line until I find where the exception is thrown. God, that's so annoying and time-wasting.

    So I'm here asking is there a way to open stack trace in Qt? Like the stack trace in Visual Studio and the backtrace in gdb(open by typing bt or backtrace).

    aha_1980A JonBJ 2 Replies Last reply
    0
    • P Offline
      P Offline
      PikaCat
      wrote on last edited by
      #13

      I find the solution to my problem. You can go to GDB Extended to check "the stop when abort() is called". Then it will stop at the line in which you throw an exception. But the problem is that there are no windows saying "Exception Triggered". That's very strange.

      aha_1980A 1 Reply Last reply
      1
      • P PikaCat
        #include<bits/stdc++.h>
        void badFunction(){
            throw std::out_of_range("");
        }
        int main(){
            badFunction();
            return 0;
        }
        

        Just like the code above. When I use debug mode to run the code, it will terminate immediately and leave only a message of terminate called after throwing out_of_range.

        Imagine this is a big project with hundreds and thousands of functions in it. When it throws an exception like this, I don't know where the exception occurred.

        In Visual Studio, it will tell you that the unhandled exception in which file, which function and which line, and when you look at that line, there is a big red cross after that code, so I can handle that easily.

        However, in Qt, I have to make a breakpoint at the beginning of the main function and trace down the code line by line until I find where the exception is thrown. God, that's so annoying and time-wasting.

        So I'm here asking is there a way to open stack trace in Qt? Like the stack trace in Visual Studio and the backtrace in gdb(open by typing bt or backtrace).

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi @PikaCat,

        if you run the program in the debugger, it will stop at the exception and show you the stack trace. If not, something is wrongly set up and you need to provide more info about your environment and setup.

        Regards

        Qt has to stay free or it will die.

        P 2 Replies Last reply
        4
        • P PikaCat
          #include<bits/stdc++.h>
          void badFunction(){
              throw std::out_of_range("");
          }
          int main(){
              badFunction();
              return 0;
          }
          

          Just like the code above. When I use debug mode to run the code, it will terminate immediately and leave only a message of terminate called after throwing out_of_range.

          Imagine this is a big project with hundreds and thousands of functions in it. When it throws an exception like this, I don't know where the exception occurred.

          In Visual Studio, it will tell you that the unhandled exception in which file, which function and which line, and when you look at that line, there is a big red cross after that code, so I can handle that easily.

          However, in Qt, I have to make a breakpoint at the beginning of the main function and trace down the code line by line until I find where the exception is thrown. God, that's so annoying and time-wasting.

          So I'm here asking is there a way to open stack trace in Qt? Like the stack trace in Visual Studio and the backtrace in gdb(open by typing bt or backtrace).

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #3

          @PikaCat
          I presume you mean in Qt Creator. I'm not a regular user so I can't give you the exact instruction, but that has a debugger interface and includes a stack trace, just like e.g. Visual Studio. (If you're doing gcc compilation then Qt debugging just sits atop gdb). So just make sure you have your compiler/debugger set up in Qt Creator, set your program off for debugging, and you'll get the backtrace in some window.

          1 Reply Last reply
          3
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #4

            Hi
            Try
            https://stackoverflow.com/questions/16735413/how-can-i-make-qtcreator-break-on-exceptions
            ( add new breakpint, dont matter where, set to Break on c++ exception )
            Then it shows the origin of the trow

            alt text

            P 1 Reply Last reply
            4
            • aha_1980A aha_1980

              Hi @PikaCat,

              if you run the program in the debugger, it will stop at the exception and show you the stack trace. If not, something is wrongly set up and you need to provide more info about your environment and setup.

              Regards

              P Offline
              P Offline
              PikaCat
              wrote on last edited by
              #5

              @aha_1980
              I'm using Qt Creator with default minGW7.3.0 64bit on Windows 10 1909. When I run the program above in debug mode it will just run normally and output a message(terminate ...) on the black console window. Then nothing shows up in the debugger window.

              1 Reply Last reply
              0
              • aha_1980A aha_1980

                Hi @PikaCat,

                if you run the program in the debugger, it will stop at the exception and show you the stack trace. If not, something is wrongly set up and you need to provide more info about your environment and setup.

                Regards

                P Offline
                P Offline
                PikaCat
                wrote on last edited by
                #6

                @aha_1980 b819d8f9-ce7a-47ea-ac1b-c1106918f0a1-image.png

                1 Reply Last reply
                0
                • mrjjM mrjj

                  Hi
                  Try
                  https://stackoverflow.com/questions/16735413/how-can-i-make-qtcreator-break-on-exceptions
                  ( add new breakpint, dont matter where, set to Break on c++ exception )
                  Then it shows the origin of the trow

                  alt text

                  P Offline
                  P Offline
                  PikaCat
                  wrote on last edited by PikaCat
                  #7

                  @mrjj After adding the breakpoint, it will stop at the exception throw line, but there are no windows like this saying "Exception Triggered".
                  Besides, the project I create is from Non-Qt Project -> Plain C++ application.

                  mrjjM 1 Reply Last reply
                  0
                  • P PikaCat

                    @mrjj After adding the breakpoint, it will stop at the exception throw line, but there are no windows like this saying "Exception Triggered".
                    Besides, the project I create is from Non-Qt Project -> Plain C++ application.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @PikaCat
                    Hmm odd it can be differnt.
                    What compiler are you using ? vs/mingw

                    P 4 Replies Last reply
                    0
                    • mrjjM mrjj

                      @PikaCat
                      Hmm odd it can be differnt.
                      What compiler are you using ? vs/mingw

                      P Offline
                      P Offline
                      PikaCat
                      wrote on last edited by
                      #9

                      @mrjj I'm using minGW7.3.0 64bit

                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @PikaCat
                        Hmm odd it can be differnt.
                        What compiler are you using ? vs/mingw

                        P Offline
                        P Offline
                        PikaCat
                        wrote on last edited by PikaCat
                        #10

                        @mrjj It's just like the program exits normally with the return value of 0. The debugger thinks that the program has already exited so it stopped showing things too. If you break on that line it stops but when you press F10, it will immediately stop execution the program.

                        1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @PikaCat
                          Hmm odd it can be differnt.
                          What compiler are you using ? vs/mingw

                          P Offline
                          P Offline
                          PikaCat
                          wrote on last edited by
                          #11

                          @mrjj I think maybe the MSVC compiler has that function but minGW doesn't. So you can see that window pops out but I can't. But minGW's debugger is gdb, you can type bt in gdb and you can see the things you need. So accordingly, even if I'm using minGW, I should still have that function like gdb does.

                          1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @PikaCat
                            Hmm odd it can be differnt.
                            What compiler are you using ? vs/mingw

                            P Offline
                            P Offline
                            PikaCat
                            wrote on last edited by
                            #12

                            @mrjj Moreover, if I add breakpoints at "Break when C++ exception is thrown", Whenever my program throws an exception. It will stop there, even if I had already caught it in the catch statement and solved it. The thing I want is the "UNHANDLED EXCEPTION". When the program doesn't handle the exception properly and cause the program to call std:: terminate() to terminate the program. QT debugger will stop there for me to see the stack trace and where the exception is thrown.

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              PikaCat
                              wrote on last edited by
                              #13

                              I find the solution to my problem. You can go to GDB Extended to check "the stop when abort() is called". Then it will stop at the line in which you throw an exception. But the problem is that there are no windows saying "Exception Triggered". That's very strange.

                              aha_1980A 1 Reply Last reply
                              1
                              • P PikaCat

                                I find the solution to my problem. You can go to GDB Extended to check "the stop when abort() is called". Then it will stop at the line in which you throw an exception. But the problem is that there are no windows saying "Exception Triggered". That's very strange.

                                aha_1980A Offline
                                aha_1980A Offline
                                aha_1980
                                Lifetime Qt Champion
                                wrote on last edited by
                                #14

                                @PikaCat said in How to open stack trace in QT?:

                                But the problem is that there are no windows saying "Exception Triggered". That's very strange.

                                Is that a big problem? If the debugger stops at a throw, you should already know what happens.

                                You can go to GDB Extended to check "the stop when abort() is called".

                                Glad you found it and thanks for sharing!

                                Regards

                                Qt has to stay free or it will die.

                                1 Reply Last reply
                                1

                                • Login

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