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()
Forum Updated to NodeBB v4.3 + New Features

How to get a backtrace from qDebug()

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 839 Views 2 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
    Perdrix
    wrote on 8 Jun 2023, 16:32 last edited by Perdrix 6 Aug 2023, 16:35
    #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

    C 1 Reply Last reply 8 Jun 2023, 17:02
    0
    • P Perdrix
      8 Jun 2023, 16:32

      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

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 8 Jun 2023, 17:02 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

      P 1 Reply Last reply 8 Jun 2023, 17:43
      2
      • C Christian Ehrlicher
        8 Jun 2023, 17:02

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

        P Offline
        P Offline
        Perdrix
        wrote on 8 Jun 2023, 17:43 last edited by Perdrix 6 Aug 2023, 17:44
        #3

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

        Sorry

        C 1 Reply Last reply 9 Jun 2023, 00:27
        0
        • P Perdrix
          8 Jun 2023, 17:43

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

          Sorry

          C Offline
          C Offline
          ChrisW67
          wrote on 9 Jun 2023, 00:27 last edited by
          #4

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

          C 1 Reply Last reply 9 Jun 2023, 05:29
          0
          • C ChrisW67
            9 Jun 2023, 00:27

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

            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 9 Jun 2023, 05:29 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

            P 1 Reply Last reply 9 Jun 2023, 14:14
            0
            • C Christian Ehrlicher
              9 Jun 2023, 05:29

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

              P Offline
              P Offline
              Perdrix
              wrote on 9 Jun 2023, 14:14 last edited by Perdrix 6 Sept 2023, 14:16
              #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 12 Jun 2023, 07:09
              0
              • P Perdrix
                9 Jun 2023, 14:14

                @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 12 Jun 2023, 07:09 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.

                P 1 Reply Last reply 12 Jun 2023, 08:28
                1
                • S SimonSchroeder
                  12 Jun 2023, 07:09

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

                  P Offline
                  P Offline
                  Perdrix
                  wrote on 12 Jun 2023, 08:28 last edited by
                  #8

                  @SimonSchroeder Good news ...

                  1 Reply Last reply
                  0

                  2/8

                  8 Jun 2023, 17:02

                  6 unread
                  • Login

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