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
qmakeruns, 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. -
R Robert Hairgrove has marked this topic as solved on
-
R Robert Hairgrove has marked this topic as unsolved on
-
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*.profile 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 forqmakein the fileQt/<version>/Src/qtbase/qmake/library/qmakebuiltins.cpp). -
R Robert Hairgrove has marked this topic as solved on
-
Solved this by the following:
Define a variable close to the top of your*.profile 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 forqmakein 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.