Results 1 to 13 of 13

Thread: Display French "ACCENT" from output QProcess

  1. #1
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Display French "ACCENT" from output QProcess

    Hii Forum,

    I have a problem with the output of QProcess

    Qt Code:
    1. m_process.start("ipconfig /all");
    2. if (!m_process.waitForStarted()) {
    3. qDebug() << "Error : " << m_process.errorString();
    4. }
    5. m_process.waitForFinished(-1); // will wait forever until finished
    6. output = m_process.readAllStandardOutput();
    7. ui->plainTextEdit_InfosConfig->setPlainText(output.toLatin1());
    To copy to clipboard, switch view to plain text mode 

    I want to display the right symbol ( é not ?)
    See Scrennshot : accents.png

    Regards,

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    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,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    Thnx for reply,

    I tried to do :
    Qt Code:
    1. m_process.waitForFinished(-1); // will wait forever until finished
    2. output = m_process.readAllStandardOutput();
    3. QByteArray str = output.toLatin1();
    4. ui->plainTextEdit_InfosConfig->setPlainText(QString::fromLocal8Bit(str));
    To copy to clipboard, switch view to plain text mode 

    the problem remains

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,525
    Thanked 279 Times in 274 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    How is defined variable output ? If it is QString You have to do something like this :
    Qt Code:
    1. output = QString::fromLocal8Bit(m_process.readAllStandardOutput());
    2. ui->plainTextEdit_InfosConfig->setPlainText(output);
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lesiok; 11th October 2016 at 18:16.

  5. #5
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    Yes,
    output is QString :
    Qt Code:
    1. QString output;
    To copy to clipboard, switch view to plain text mode 

    I already tried this method

    Not resolved

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,525
    Thanked 279 Times in 274 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    If it is On windows check with chcp command what is console code page.

  7. #7
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    Cmd : chcp
    Qt Code:
    1. Page de codes active*: 850
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    Quote Originally Posted by Binary01 View Post
    Thnx for reply,

    I tried to do :
    Qt Code:
    1. m_process.waitForFinished(-1); // will wait forever until finished
    2. output = m_process.readAllStandardOutput();
    3. QByteArray str = output.toLatin1();
    4. ui->plainTextEdit_InfosConfig->setPlainText(QString::fromLocal8Bit(str));
    To copy to clipboard, switch view to plain text mode 

    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,
    _

  9. #9
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,525
    Thanked 279 Times in 274 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    Quote Originally Posted by Binary01 View Post
    Cmd : chcp
    Qt Code:
    1. Page de codes active*: 850
    To copy to clipboard, switch view to plain text mode 
    So try this
    Qt Code:
    1. QTextCodec *codec = QTextCodec::codecForName("IBM850");
    2. output = codec->toUnicode(m_process.readAllStandardOutput());
    3. ui->plainTextEdit_InfosConfig->setPlainText(output);
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    Good job @lesiok

    It works, Thanks

  11. #11
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,525
    Thanked 279 Times in 274 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    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.

  12. #12
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    Hiii,

    I tried the same code in other windows (64 bits), the program crash in :
    Qt Code:
    1. QTextCodec *codec = QTextCodec::codecForName("IBM850");
    To copy to clipboard, switch view to plain text mode 

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

    e.g : cmd chcp :
    Qt Code:
    1. Page de codes active: 850
    To copy to clipboard, switch view to plain text mode 

    Regards;

  13. #13
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display French "ACCENT" from output QProcess

    Depending on why you run that program you could have options to call API instead and avoid all encoding issues.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 11:02
  2. Replies: 3
    Last Post: 16th March 2015, 08:31
  3. xlib: extension "XFree86-DRI" missing on display ":0.0".
    By kiransu123 in forum Qt Programming
    Replies: 5
    Last Post: 3rd August 2009, 15:43
  4. Replies: 0
    Last Post: 3rd December 2008, 12:58
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.