Read output Terminal with QProcess



  • Hi,

    I try to read output of terminal with accent like this:

    //Read interface
        cmd = QString("netsh interface show interface");
        p.start(cmd);
        p.waitForFinished();
    
        QStringList list1;
        while(!p.atEnd())
        {
            list1.append(p.readLine());
        }
    
        qDebug() << list1;
    

    And my list1 =

    ("\r\n", "\uFFFDtat admin    \uFFFDtat          Type            Nom de l'interface\r\n", "-------------------------------------------------------------------------\r\n", "Activ\uFFFD         D\uFFFDconnect\uFFFD     D\uFFFDdi\uFFFD            Ethernet\r\n", "Activ\uFFFD         Connect\uFFFD       D\uFFFDdi\uFFFD            Connexion au r\uFFFDseau local* 13\r\n", "Activ\uFFFD         Connect\uFFFD       D\uFFFDdi\uFFFD            VirtualBox Host-Only Network\r\n", "Activ\uFFFD         Connect\uFFFD       D\uFFFDdi\uFFFD            VirtualBox Host-Only Network #2\r\n", "Activ\uFFFD         Connect\uFFFD       D\uFFFDdi\uFFFD            Wi-Fi\r\n", "Activ\uFFFD         D\uFFFDconnect\uFFFD     D\uFFFDdi\uFFFD            Ethernet 2\r\n", "\r\n")
    

    I don't know how reomve this \uFFFD normaly it's "é" char.

    Someone can help me to fix this ?

    Thanks



  • Hi,

    I would assume that the contents of list1 is correct, but that qDebug does not ise an encoding in the output.

    -Michael.



  • Exactlly !!!!

    i have tried some QString::fromUtf8 ...

    But never accent :(



  • @Franckynos

    Hi.

    Your console output contains the local charset.
    You can try QString::fromLocal8Bit() instead of QString::fromUtf8().
    Like this:

    list1.append(QString::fromLocal8Bit(p.readLine()));
    


  • I have already try this but \uFFFD is replace by \u201A

    Activ\u201A         D\u201Aconnect\u201A     D\u201Adi\u201A            Ethernet 2\r\n", "\r\n"
    

  • Moderators

    @Franckynos What encoding is your terminal using?


  • Lifetime Qt Champion

    Hi,

    You might also see the qDebug behaviour change described here.



  • @SGaist thx your have right, i have the 5.5.0.


Log in to reply