qDebug() with color
-
wrote on 27 Aug 2023, 10:37 last edited by
Is it possible to qDebug current line with some color?
-
Is it possible to qDebug current line with some color?
wrote on 27 Aug 2023, 11:10 last edited by@JacobNovitsky
You could send terminal color escape codes, but I don't think the Qt Creator debug Application Output window (it's not a "terminal") displays them or color in any user-controllable way, if that is what you mean. -
Is it possible to qDebug current line with some color?
@JacobNovitsky qDebug just outputs a string to debug stream. Coloring is a function of the particular terminal/window/device that presents the stream. There's no single standard for coloring text. The receiver might not even support color. You have to refer to the specifics of your output.
For example Qt Creator Application Output supports ANSI escape sequences, so this
qDebug() << "\033[31mHello, I'm red text\033[0m";
will print text "Hello, I'm red text" in red and then reset the color to defaults. Note that it will not work on all output devices, only those supporting ANSI codes.
-
@JacobNovitsky qDebug just outputs a string to debug stream. Coloring is a function of the particular terminal/window/device that presents the stream. There's no single standard for coloring text. The receiver might not even support color. You have to refer to the specifics of your output.
For example Qt Creator Application Output supports ANSI escape sequences, so this
qDebug() << "\033[31mHello, I'm red text\033[0m";
will print text "Hello, I'm red text" in red and then reset the color to defaults. Note that it will not work on all output devices, only those supporting ANSI codes.
wrote on 27 Aug 2023, 16:34 last edited by@Chris-Kawa said in qDebug() with color:
For example Qt Creator Application Output supports ANSI escape sequences
That I didn't know, I thought it was raw output.
1/4