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 get a backtrace from qDebug()

How to get a backtrace from qDebug()

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 825 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    Trying to get a backtrace from qDebug()

    In my startup code I wrote:

    	qSetMessagePattern("%{if-category}%{category}: %{endif}%{message}%{backtrace}");
    

    thinking that would get me a backtrace.

    Unfortunately I didn't get a backtrace.

    qDebug() << __FUNCTION__; 
    

    just got me e.g.:

    DSS::ProgressLive::Start2
    

    What did I do wrong?
    Thanks
    David

    Christian EhrlicherC 1 Reply Last reply
    0
    • PerdrixP Perdrix

      Trying to get a backtrace from qDebug()

      In my startup code I wrote:

      	qSetMessagePattern("%{if-category}%{category}: %{endif}%{message}%{backtrace}");
      

      thinking that would get me a backtrace.

      Unfortunately I didn't get a backtrace.

      qDebug() << __FUNCTION__; 
      

      just got me e.g.:

      DSS::ProgressLive::Start2
      

      What did I do wrong?
      Thanks
      David

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Perdrix said in How to get a backtrace from qDebug():

      Unfortunately I didn't get a backtrace.

      Did you read the docs?

      "A backtrace with the number of frames specified by the optional depth parameter (defaults to 5), and separated by the optional separator parameter (defaults to "|"). This expansion is available only on some platforms (currently only platfoms using glibc). Names are only known for exported functions. If you want to see the name of every function in your application, use QMAKE_LFLAGS += -rdynamic."

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      PerdrixP 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        @Perdrix said in How to get a backtrace from qDebug():

        Unfortunately I didn't get a backtrace.

        Did you read the docs?

        "A backtrace with the number of frames specified by the optional depth parameter (defaults to 5), and separated by the optional separator parameter (defaults to "|"). This expansion is available only on some platforms (currently only platfoms using glibc). Names are only known for exported functions. If you want to see the name of every function in your application, use QMAKE_LFLAGS += -rdynamic."

        PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by Perdrix
        #3

        @Christian-Ehrlicher Oh! I missed the bit about glibc - so no backtrace on Windows :(

        Sorry

        C 1 Reply Last reply
        0
        • PerdrixP Perdrix

          @Christian-Ehrlicher Oh! I missed the bit about glibc - so no backtrace on Windows :(

          Sorry

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          @Perdrix Unless you are using the MingW toolchain I expect.

          Christian EhrlicherC 1 Reply Last reply
          0
          • C ChrisW67

            @Perdrix Unless you are using the MingW toolchain I expect.

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @ChrisW67 said in How to get a backtrace from qDebug():

            Unless you are using the MingW toolchain I expect.

            No - as stated in the documentation you need glibc.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            PerdrixP 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @ChrisW67 said in How to get a backtrace from qDebug():

              Unless you are using the MingW toolchain I expect.

              No - as stated in the documentation you need glibc.

              PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by Perdrix
              #6

              @Christian-Ehrlicher I used StackWalker https://github.com/JochenKalmbach/StackWalker to get the back trace I needed.

                  StackWalker sw;
                  sw.ShowCallstack();
              

              It's a shame this isn't part of Qt!

              D.

              S 1 Reply Last reply
              0
              • PerdrixP Perdrix

                @Christian-Ehrlicher I used StackWalker https://github.com/JochenKalmbach/StackWalker to get the back trace I needed.

                    StackWalker sw;
                    sw.ShowCallstack();
                

                It's a shame this isn't part of Qt!

                D.

                S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #7

                C++23 includes std::stacktrace. So, we'll have a standardized solution in the future when C++23 is widely adopted.

                PerdrixP 1 Reply Last reply
                1
                • S SimonSchroeder

                  C++23 includes std::stacktrace. So, we'll have a standardized solution in the future when C++23 is widely adopted.

                  PerdrixP Offline
                  PerdrixP Offline
                  Perdrix
                  wrote on last edited by
                  #8

                  @SimonSchroeder Good news ...

                  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