Mimic console behavior in QTextArea

24 Views Asked by At

When I execute some console applications, often I see an ASCII progress bar, like this:

  8%   6.8 KiB |###                                     | Elapsed Time: 0:00:00

when the values change, the row is still the same, like it was overwritten. I'm trying to capture such an output from a QProcess and to append it to a QTextArea:

void MyProcess::process_readyRead()
{
    while (_process.canReadLine())
    {
        QString msg = _process.readLine();
        emit messageChanged(msg);
    }
}

somewhere:

connect(&myProcess, &MyProcess::messageChanged, ui->textArea, &QTextEdit::append);

But I see one line after another. Inspecting the captured lines I noticed there are no special characters:

"  0%   0.0 B |                                          | Elapsed Time: 0:00:00\n"
"  1%   1.2 KiB |                                        | Elapsed Time: 0:00:00\n"
"  2%   2.1 KiB |#                                       | Elapsed Time: 0:00:00\n"
"  3%   3.1 KiB |#                                       | Elapsed Time: 0:00:00\n"
"  5%   4.0 KiB |##                                      | Elapsed Time: 0:00:00\n"
"  6%   4.9 KiB |##                                      | Elapsed Time: 0:00:00\n"
"  7%   5.9 KiB |##                                      | Elapsed Time: 0:00:00\n"
"  8%   6.8 KiB |###                                     | Elapsed Time: 0:00:00\n"

How can the console show only these lines on the same row, while other outputs are appended below?

How to mimic the same behavior on a QTextArea in Qt6.x?

0

There are 0 best solutions below