Home > OS >  About QT5 Qprocess output in Ubuntu
About QT5 Qprocess output in Ubuntu

Time:04-24

I use QT to call external programs under Ubuntu and put the output on textbrowser. However, because the external programs I want to call have colors in the shell output, the output of textbrowser is mixed with color codes. How can I remove them?

enter image description here

enter image description here

CodePudding user response:

Normally programs perform check if output is tty (terminal) and only output text with colors if it is. Do you have escape codes when you redirect output to file?

To strip color codes from terminal you can use regular expression. Check answers to this question: Removing colors from output

CodePudding user response:

In SWI-Prolog Qt console I wrote this class for matching ANSI coloring sequences that must be cleaned. I replace them with the appropriate QTextCharFormat commands, you can work out something similar, replacing instead with empty strings or the CSS styling as required by your application. Inside the source (both ansi_esc_seq.h and ansi_esc_seq.cpp) you also find a bit of documentation about the not-so-easy-to-find ANSI escape sequences behaviour.

  • Related