PDA

View Full Version : Display French "ACCENT" from output QProcess



Binary01
11th October 2016, 13:41
Hii Forum,

I have a problem with the output of QProcess


m_process.start("ipconfig /all");
if (!m_process.waitForStarted()) {
qDebug() << "Error : " << m_process.errorString();
}
m_process.waitForFinished(-1); // will wait forever until finished
output = m_process.readAllStandardOutput();
ui->plainTextEdit_InfosConfig->setPlainText(output.toLatin1());

I want to display the right symbol ( é not ?)
See Scrennshot : 12159

Regards,

anda_skoa
11th October 2016, 14:11
Well, maybe your system isn't configured to have UTF-8 as the shell process encoding.

Which you do assume here since you are assigning a QByteArray to a QString and that by default converts from UTF-8.

You can also convert to latin1 and then back to QString using UTF-8 again.

I would recommend using QString::fromLocal8Bit() for the "read" conversion.

Cheers,
_

Binary01
11th October 2016, 14:59
Thnx for reply,

I tried to do :

m_process.waitForFinished(-1); // will wait forever until finished
output = m_process.readAllStandardOutput();
QByteArray str = output.toLatin1();
ui->plainTextEdit_InfosConfig->setPlainText(QString::fromLocal8Bit(str));

the problem remains

Lesiok
11th October 2016, 15:44
How is defined variable output ? If it is QString You have to do something like this :
output = QString::fromLocal8Bit(m_process.readAllStandardOu tput());
ui->plainTextEdit_InfosConfig->setPlainText(output);

Binary01
11th October 2016, 16:12
Yes,
output is QString :
QString output;

I already tried this method

Not resolved

Lesiok
11th October 2016, 17:18
If it is On windows check with chcp command what is console code page.

Binary01
11th October 2016, 17:26
Cmd : chcp

Page de codes active*: 850

anda_skoa
11th October 2016, 18:53
Thnx for reply,

I tried to do :

m_process.waitForFinished(-1); // will wait forever until finished
output = m_process.readAllStandardOutput();
QByteArray str = output.toLatin1();
ui->plainTextEdit_InfosConfig->setPlainText(QString::fromLocal8Bit(str));

the problem remains

So you ignore my suggestion and are wondering why the problem remains?
Maybe try to follow the suggestion before posting again?

Cheers,
_

Lesiok
12th October 2016, 06:59
Cmd : chcp

Page de codes active*: 850So try this
QTextCodec *codec = QTextCodec::codecForName("IBM850");
output = codec->toUnicode(m_process.readAllStandardOutput());
ui->plainTextEdit_InfosConfig->setPlainText(output);

Binary01
12th October 2016, 16:32
Good job @lesiok

It works, Thanks

Lesiok
12th October 2016, 17:02
Windows schizophrenia ;) It uses two code pages : one for GUI and another for cmd. Qt's "local8bit" functions detects GUI cp so QString::fromLocal8bit is not working in this case.

Binary01
13th October 2016, 20:42
Hiii,

I tried the same code in other windows (64 bits), the program crash in :
QTextCodec *codec = QTextCodec::codecForName("IBM850");

Is there a way to standardize this method or using an other way ???

e.g : cmd chcp :
Page de codes active: 850

Regards;

anda_skoa
14th October 2016, 10:16
Depending on why you run that program you could have options to call API instead and avoid all encoding issues.

Cheers,
_