This question has already been answered:

How to read the data (and output to the console) so that the string is normal without escape characters and that individual words are not replaced with byte encoding, for example, Connected. What is the problem?

#include <QCoreApplication> #include <QProcess> #include <QDebug> #include <QTextCodec> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QProcess *console = new QProcess(); QStringList aList; console->start( "ipconfig" ); QByteArray aOut; if( console->waitForFinished( ) == true ) { aOut = console->readAllStandardOutput(); } QTextCodec *codec = QTextCodec::codecForName( "Windows-1251" ); QString sOut = codec->toUnicode( aOut ); qDebug() << sOut; return a.exec(); } 

enter image description here

Reported as a duplicate by jfs , Harry c ++ Oct 18 '17 at 12:14 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • try to convert like this QString sOut = codec->toUnicode( QString(aOut).toLocal8Bit() ); - it will help a little. - KoVadim
  • KoVadim unfortunately did not help, now instead of cyrillic letters there are question marks - Evgeny Druzhinin
  • one
    I still can not check - I only have English-speaking Windows ... And on English-speaking everything is ok. Maybe there all the same coding 866, but not cp1251? - KoVadim
  • KoVadim cp-866 leads to the appearance of krakozyabry - Evgeny Druzhinin
  • one
    Yes, yes, that's right. and they should be. do not output to the console, but the file and open it with a notepad (or its substitutes). You read from the console, which is 866 and then tried to convert it to cp1251-> unicode. It turned out in part (which you actually saw). In the latter case, we saw "cracks" because it looks like this, printed on 866. - KoVadim

1 answer 1

The terminal in Windows (if no one touched anything), works in 866 encoding. It is different from cp1251 encodings and unicode. In your original code, you are trying to decode 866 encoding as cp1251 to Unicode (this is interesting) and output the result to the screen, where it is interpreted as 866. Most likely, the conversion was partially completed and only damaged some characters, and the output was successful (almost).

Thanks to Microsoft, which is trying to do supercompatibility with all its might, there are several incompatible encodings inside Windows that need to be remembered. The terminal operates at 866 (the old DOS encoding). Qt mainly uses Unicode (as well as the core of modern Windows). cp1251 uses mostly old programs and now it is slowly moving away to another world.

Therefore, most likely, in order to work correctly, you need to convert all the input yourself in Unicode. And when you need to withdraw - convert to 866 back.