Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to view Backtrace / Stacktrace?



  • I am having one heck of a time figuring out how to view Stacktrace / Backtrace info.

    I can not find any good documentation that shows how I can set this up or view it. If you know of a way to view the stacktrace / backtrace within Qt, please let me know.

    I have found documention on Qt titled "Viewing Call Stack Trace" which does not explain how to view this Stack view. I set breakpoints and the program does not seem to break and I can not see any further detailed information in my Issues, Application Output, or other tabs.

    I found "StackView" which appears to be available with QML, however, I am not using QML.

    It appears the QDebug class does not offer anything for calling or working with a stacktrace / backtrace.

    Other people have created whole new classes to deal with Stacktracing, however, all these seem to be very old methods.

    Is construction my own StackTrace class something that people do in Qt to debug their program? Qt not have a native way to view the stack trace?

    Here are ways that I found where I would need to create my own stack trace class:

    Walking the callstack
    Printing a Stack Trace with MinGW
    Qt C++ Unhandled exceptions stack trace
    How to automatically generate a stacktrace when my program crashes


  • Moderators

    You don't have to write any code to view the stack trace unless you're writing a debugger or want to have debugger-like features in your app.

    If you just want to vie the stack trace of your own app in Qt Creator just make sure about these things:

    qtcreator debugger

    • Check that you're actually running a debug version of the app, not release (See the picture above)
    • Make sure you've got a debugger automatically configured for your kit. Go to Tools -> Options -> Kits -> Kits tab, select a kit you're using and check if the "Debugger" field in its properties is set. Post a picture of that page if you're in doubt.
    • Make sure you're actually starting a debug session and not a run session i.e. the green arrow with bug icon in the picture above.

    With that all you need to do is set a breakpoint (F9 or click on the left margin of your code) and it should stop the app's execution at that point and a stack trace panel will show up automaticaly below your code when the breakpoint is hit.


  • Moderators

    You don't have to write any code to view the stack trace unless you're writing a debugger or want to have debugger-like features in your app.

    If you just want to vie the stack trace of your own app in Qt Creator just make sure about these things:

    qtcreator debugger

    • Check that you're actually running a debug version of the app, not release (See the picture above)
    • Make sure you've got a debugger automatically configured for your kit. Go to Tools -> Options -> Kits -> Kits tab, select a kit you're using and check if the "Debugger" field in its properties is set. Post a picture of that page if you're in doubt.
    • Make sure you're actually starting a debug session and not a run session i.e. the green arrow with bug icon in the picture above.

    With that all you need to do is set a breakpoint (F9 or click on the left margin of your code) and it should stop the app's execution at that point and a stack trace panel will show up automaticaly below your code when the breakpoint is hit.


  • Lifetime Qt Champion

    Hi
    So when you run as @Chris-Kawa describes
    then you should see this.

    alt text



  • Thanks to both of you guys so much! That helped immensely :)

    Exactly what I was looking for!


  • Lifetime Qt Champion

    Hi @AwesomeBoxhead,

    so if your problem is solved, please don't forget to mark this topic as SOLVED too. Thanks!


Log in to reply