Qt Creator: log(message) doesn't print any output
-
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 themessage(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? -
OK, I found it.
log()
is written to Compile output. -
-
-
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 prependsProject MESSAGE:
to every single line of output, which is why I wanted to uselog()
in the first place.So the question is, how to get nicely-formatted output from
log()
? -
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 runtimefputs()
function (which I found by looking in the source code forqmake
in the fileQt/<version>/Src/qtbase/qmake/library/qmakebuiltins.cpp
). -
-
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 runtimefputs()
function (which I found by looking in the source code forqmake
in the fileQt/<version>/Src/qtbase/qmake/library/qmakebuiltins.cpp
).@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.