[Interest] QPlainTextEdit and a Unicode file
Scott Aron Bloom
scott.bloom at onshorecs.com
Thu Apr 11 03:02:01 CEST 2013
I have done exactly that, how can I get a list of valid "codec" names to put in a combo box, so that the user can select one?
What I do to set the codec, is the following
QTextCodec * codec = QTextCodec::codecForName( codecName );
if ( codec )
QTextCodec::setCodecForLocale( codec );
From: interest-bounces+scott.bloom=onshorecs.com at qt-project.org [mailto:interest-bounces+scott.bloom=onshorecs.com at qt-project.org] On Behalf Of Thiago Macieira
Sent: Wednesday, April 10, 2013 5:55 PM
To: interest at qt-project.org
Subject: Re: [Interest] QPlainTextEdit and a Unicode file
On quarta-feira, 10 de abril de 2013 23.59.05, Scott Aron Bloom wrote:
> The Loading process is as follows:
> QByteArray contents = fi.readAll();
> setPlainText( contents );
The last line here will error out saying that you're converting from QByteArray to QString.
Whenever you do that, you need to tell what codec to use.
If your next question is "how do I detect the encoding of a file", the answer is that you don't. Detecting the encoding is a guessing scenario. Certain libs have a good guess ratio, but it's still a guess.
If you must *know* the encoding, you should add the drop-down combobox to your open dialog, or you have to add a menu to change the encoding (and reload the file).
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest