Unsolved QProcess german umlauts... plz help me found no solution :-(
-
Hi,
after hours of searching and testing, i ve found no solution for my problem.i execute an command via qprocess and read the text back with readAll().
This part works without any issue.
i try to convert the QByteArray from ReadAll to QString,
but after that the german umlauts äüö are missing.
i ve tried several conversion, only the hard code solution is working, but that is a bad style.if i try to get the codepage from the cmd i get only "System"
i try- m_result.append(QString::fromLocal8Bit(tmp)
the result is:
Datentr�ger in Laufwerk C
....test::test(QWidget *parent) :QDialog(parent), m_ui(new Ui::find_help) { m_ui->setupUi(this); m_process_state = new QProcess(); QString cmd = "C:/windows/system32/cmd.exe"; QStringList arguments = QStringList() << "/C" << "dir"; m_process_state->start(cmd, arguments); connect(m_process_state, SIGNAL(readyReadStandardOutput()), this, SLOT(read_result())); connect(m_process_state, SIGNAL(finished(int)), this, SLOT(read_finished())); } void test::read_result(void) { QByteArray tmp = m_process_state->readAll(); //Works but codec is hard codec, bad style //QTextCodec *pCodec = QTextCodec::codecForName("IBM-850"); //m_result.append(pCodec->toUnicode(tmp)); //m_result.append(QString::fromLocal8Bit(tmp); not working m_result.append(tmp); }
thanks a lot for the answer!
-
-
Hello,
thanks for the reply, great idea!
but i have the same problem with the cmd
netsh advfirewall firewall show rule rulenamesome suggestion for that?
thanks
-
@qt_qt said in QProcess german umlauts... plz help me found no solution :-(:
some suggestion for that?
Since it's the windows console - try to avoid it by using e.g. PowerShell (which properly can handle UTF-8) or even better WinAPI calls . Otherwise you have to hardcode it.
-
@qt_qt Hello, I found somewhere that Windows 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.
To find out the code page for the console start: "chcp" in a console. In my case, I got this (I am using French Windows 10/64bit):
c:\>chcp Page de codes active : 850
So this should work:
QTextCodec *codec = QTextCodec::codecForName("IBM850"); QString output = codec->toUnicode(m_process_state.readAll());
-
@qt_qt
I faced a similarish a while ago, as per my https://forum.qt.io/topic/87438/problem-processing-output-from-qprocess/12. You can adapt that to get the correct current Windows code page by looking at https://stackoverflow.com/a/41763796/489865. It's ugly having to get the right codepage via callingchcp.com
, I don't know if there is a native Windows call you could use to achieve that more neatly. [EDIT: I think see https://docs.microsoft.com/en-gb/windows/win32/api/winnls/nf-winnls-getoemcp & https://docs.microsoft.com/en-gb/windows/win32/api/winnls/nf-winnls-getacp .] Food for thought.