Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. Getting line code from qdebug
Qt 6.11 is out! See what's new in the release blog

Getting line code from qdebug

Scheduled Pinned Locked Moved The Lounge
8 Posts 5 Posters 7.1k 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.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    To trolls: may i suggest you to add to qdebug the number of line where it is called, please?

    1Main {
    2 qdebug()<<"number: ";
    3}
    Output:
    Number 2

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      The C++ standard defines the macro name <code>_ _ LINE _ _</code>, which expands to the line number of the current source line.

      @
      qDebug() << "number: " << LINE;
      @

      And please change your topic title to something reasonable. Thanks.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Thanatos.jsse
        wrote on last edited by
        #3

        Wow, I see why you are Area 51 Engineer...
        Thank you for this tip.

        BR,

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          There is a big discussion on that very subject on development mailing list. Here's a link to a pretty much random post (the talk is really long, you'll have to read it anyway to get to know what was decided): "link":http://lists.qt-project.org/pipermail/development/2012-February/001789.html.

          Idea is to expand logging a lot more than just the line number.

          (Z(:^

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            there are a couple of more "standard makros":http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html to be of use

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              [quote author="sierdzio" date="1328799835"]There is a big discussion on that very subject on development mailing list. Here's a link to a pretty much random post (the talk is really long, you'll have to read it anyway to get to know what was decided): "link":http://lists.qt-project.org/pipermail/development/2012-February/001789.html.

              Idea is to expand logging a lot more than just the line number.[/quote]

              Thanks for the link - todays bedtime story.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                spode
                wrote on last edited by
                #7

                What about if i want to get the same output from the following?

                @
                Write(qstring msg) { qdebug()<<msg;

                Main(){
                Write("bla");
                }
                @

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  I don't think that's possible, as the macro always expands to the current line. But you might use the preprocessor to simulate the behaviour.

                  @
                  #define write(msg) writeLine(LINE, msg)

                  void writeLine(int line, QString msg)
                  {
                  qDebug() << line << msg;
                  }

                  ...
                  write("message"); // 9 "message"
                  @

                  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