1

I have a QTextBrowser in which I display the output contents of an external binary using QProcess in Linux. All is GOOD! But most of the contents are just boxes, so now it's the character encoding UTF-8 is missing and I need to tell this to the QTextBrowser. Is there any way for that?

The code:

....
processRAM = new QProcess();
processRAM->start("memtester", QStringList() << "1" << "1");
.....
connect(processRAM, SIGNAL(readyRead()),this,SLOT(displayRAMTestOutput()));
......
void MainWindow::displayRAMTestOutput()
{
  textBrowserData->append(Qtring::fromUtf8(processRAM->readAllStandardOutput())));
}  

I added the char encoding UTF-8 and still I see only boxes. What am I missing here?

Mat
  • 202,337
  • 40
  • 393
  • 406
jxgn
  • 741
  • 2
  • 15
  • 36

1 Answers1

2

You can set content of QTextBrowser in this way:

textBrowser->setText(QString::fromUtf8(processOutput)));

EDIT: Your problem with "boxes" isn't connected with UTF8 encoding. Symbols which you see are control characters which are used by memtester when it displays text to console. If you don't want to display such characters in textBrowser, you can filter output:

while(!processRAM->atEnd())
{
    QString out = QString::fromAscii(processRAM->readLine());
    if(!out.contains("\b"))
        textBrowser->append(out);}
}

\b means backspace which is displayed in you textBrowser as boxes.

trivelt
  • 1,913
  • 3
  • 22
  • 44
  • Thanks. I tried but no luck. I have edited my question. Can you please let me know what to be done there? – jxgn Apr 15 '15 at 05:51
  • Instead of looping in while, I can have it the same way as I have now right? Plus I had to use fromLatin1 instead of fromAscii for Qt5, and still no luck :( still it is printing those boxes – jxgn Apr 15 '15 at 09:04
  • Sorry, it's my bad - you don't need to use `fromLatin1` or `fromAscii`. The way in which you filter received output `QString` is your choice, I only pointed out that your "boxes" are backspace characters and removing them is simple. – trivelt Apr 15 '15 at 09:19
  • Thanks for your help :) It solved the problem :) New learning :) thank you :) – jxgn Apr 15 '15 at 09:32