Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess german umlauts... plz help me found no solution :-(
Forum Updated to NodeBB v4.3 + New Features

QProcess german umlauts... plz help me found no solution :-(

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 541 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qt_qt
    wrote on last edited by
    #1

    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!

    KroMignonK 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use QDir::entryList()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • Q Offline
        Q Offline
        qt_qt
        wrote on last edited by
        #3

        Hello,
        thanks for the reply, great idea!
        but i have the same problem with the cmd
        netsh advfirewall firewall show rule rulename

        some suggestion for that?

        thanks

        JonBJ 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • Q qt_qt

            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!

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #5

            @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());
            

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            1
            • Q qt_qt

              Hello,
              thanks for the reply, great idea!
              but i have the same problem with the cmd
              netsh advfirewall firewall show rule rulename

              some suggestion for that?

              thanks

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @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 calling chcp.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.

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved