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. Qt Creator: log(message) doesn't print any output
Forum Updated to NodeBB v4.3 + New Features

Qt Creator: log(message) doesn't print any output

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
5 Posts 2 Posters 79 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote last edited by
    #1

    According to the docs at https://doc.qt.io/qt-6/qmake-test-function-reference.html#log-message, Qt Creator/QMake has a log(message) function in addition to the message(message) function.

    However, when qmake runs, nothing is written to the "General Messages" pane. I am using Qt Creator 17.0.1 on Linux Ubuntu 24.04 with Qt 6.9.2.

    Where does the output of log() get written?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Robert Hairgrove
      wrote last edited by
      #2

      OK, I found it. log() is written to Compile output.

      1 Reply Last reply
      0
      • R Robert Hairgrove has marked this topic as solved
      • R Robert Hairgrove has marked this topic as unsolved
      • R Offline
        R Offline
        Robert Hairgrove
        wrote last edited by Robert Hairgrove
        #3

        Now that I have found the output, I am having trouble formatting it. According to the docs, which I read carefully, it says:

        Unlike the message function, neither prepends text nor appends a line break...

        So I dutifully insert the line feeds myself as "\n" in the text. However, instead of writing an actual line feed to the output, I get the "\n" as literal tokens! When I escape the line feed token as "\\n", I get "\n\n". But no actual line feed.

        I could use the message() function, but as the docs say, this prepends Project MESSAGE: to every single line of output, which is why I wanted to use log() in the first place.

        So the question is, how to get nicely-formatted output from log()?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Robert Hairgrove
          wrote last edited by
          #4

          Solved this by the following:
          Define a variable close to the top of your *.pro file which stores the result of $$escape_expand(\\n), e.g.:

          NL = $$escape_expand(\\n)
          

          When you want to use log("some string"), with a newline at the end, write it like this:

          log("some string$${NL}")
          

          Quirky, but it works.

          Apparently, the log() function is a thin wrapper around the C runtime fputs() function (which I found by looking in the source code for qmake in the file Qt/<version>/Src/qtbase/qmake/library/qmakebuiltins.cpp).

          SGaistS 1 Reply Last reply
          2
          • R Robert Hairgrove has marked this topic as solved
          • R Robert Hairgrove

            Solved this by the following:
            Define a variable close to the top of your *.pro file which stores the result of $$escape_expand(\\n), e.g.:

            NL = $$escape_expand(\\n)
            

            When you want to use log("some string"), with a newline at the end, write it like this:

            log("some string$${NL}")
            

            Quirky, but it works.

            Apparently, the log() function is a thin wrapper around the C runtime fputs() function (which I found by looking in the source code for qmake in the file Qt/<version>/Src/qtbase/qmake/library/qmakebuiltins.cpp).

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote last edited by
            #5

            @Robert-Hairgrove this brought back some memories ! I don't remember exactly why I needed that but that trick was very good to know.
            I think I needed to build a set of commands to be execute or something like that.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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