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.

 

Posted in

Leave a Reply