I want to get the output from a sub-process that I created by QProcess. The code looks like follows:
while(this->m_pythonProcess.canReadLine()){
QByteArray output_line = this->m_pythonProcess.readLine();
this->m_output.append(output_line);
this ->m_ouput
is an instance of QPlainTextEditor. I found the output_line could not display correctly if there are Chinese characters because it is encoded in GB2312. How do you convert it into Unicode so that the QPlainTextEditor class could display it correctly?
I tried QStringDecoder class to convert it, but it failed. The code is as follows:
while(this->m_pythonProcess.canReadLine()){
QByteArray output_line = this->m_pythonProcess.readLine();
QStringDecoder toUtf16 = QStringDecoder(QStringDecoder::Utf8);
QString string = toUtf16(output_line);
this->m_output.append(string);
}