qmake escape_expand

How do you display multiple-line messages in .pro file? The following code does not work.

message(“First line\nSecond line”)

The backslash is indeed an escape character in the string, but it can only escape one character, i.e, the backslash itself. So the following two lines output the same: First line\nSecond line

message(“First line\nSecond line”)

message(“First line\\nSecond line”)

Similarly \r, \t do not work as well. To display messages in multiple lines, you should use the built-in qmake function escape_expand:

message(“First line$$escape_expand(\n)Second line”)

Since \ can escape \ itself, the following code gets the same result:

message(“First line$$escape_expand(\\n)Second line”)

The official document about escape_expand is not accurate. You do not need to escape the backslash.


If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply