| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
If I read in a string containing various scandanavian, Bulgarian,
Vietnamese and other non-ASCII characters I can write it out on Windows
like this:
QString s;
...
// read non-ascii chars into s
...
QFile f( "out.txt" );
if ( f.open( QIODevice::WriteOnly | QIODevice::Text |
QIODevice::Truncate ) )
{
QTextStream t( &f );
t.setCodec( "UTF-8" );
t << s;
f.close();
}
I can open out.txt in notepad and all the non-ascii chars are fine.
But I can't get it to work on Mac OS X. If I preview the contents of the
file in Finder or display the file contents in TextEdit.app the
non-ascii chars are garbage (but they look fine if I write them to a
HTML file with content set to UTF-8).
I have tried changing the encoding to "UTF-16" and
QTextCodec::codecForLocale()->name() and converting the string using
QString::toLocal8Bit(). I still can't get it correctly encoded for Mac
OS X. What am I doing wrong? What encoding does Mac OS X expect for text
files? I can't find anything in the documentation or archives.
thanks in advance
Andy Brice
http://www.perfecttableplan.com
http://www.successfulsoftware.net
--
[ signature omitted ]
Hello Andy.
Now I'm on mine Mac
For checking which encoding you're running in the terminal run the
export command
and look in output for declare -x LC_CTYPE
In mine case it's declare -x LC_CTYPE="UTF-8". But I've a problem
with output of qDebug() << "текст по-русски". But no problem If I do
qDebug() << tr("текст по-русски");
Which encoding is yours ?
Best regards,
Ilya Dyoshin
--
[ signature omitted ]
Ilya Dyoshin wrote:
>In mine case it's declare -x LC_CTYPE="UTF-8". But ÂI've Âa problem Â
>with output of qDebug() << "ÑÐÐÑÑ ÐÐ-ÑÑÑÑÐÐ". But no problem If I do Â
>qDebug() << tr("ÑÐÐÑÑ ÐÐ-ÑÑÑÑÐÐ");
qDebug is restricted to ASCII. Anything else it'll corrupt.
--
[ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
Ilya Dyoshin wrote:
> Hello Andy.
>
> Now I'm on mine Mac
>
> For checking which encoding you're running in the terminal run the
> export command
>
> and look in output for declare -x LC_CTYPE
>
> In mine case it's declare -x LC_CTYPE="UTF-8". But I've a problem
> with output of qDebug() << "текст по-русски". But no problem If I do
> qDebug() << tr("текст по-русски");
>
> Which encoding is yours ?
>
>
> Best regards,
> Ilya Dyoshin
>
>
>
>
Ilya,
I have:
declare -x __CF_USER_TEXT_ENCODING="0x1F5:0:0"
But no "declare -x LC_CTYPE".
I don't know what that means or where it is set from. This is on MacOSX
10.4.
best regards
Andy Brice
--
[ signature omitted ]
Andy Brice wrote:
> If I read in a string containing various scandanavian, Bulgarian,
> Vietnamese and other non-ASCII characters I can write it out on Windows
> like this:
>
> QString s;
> ...
> // read non-ascii chars into s
> ...
> QFile f( "out.txt" );
> if ( f.open( QIODevice::WriteOnly | QIODevice::Text |
> QIODevice::Truncate ) )
> {
> QTextStream t( &f );
> t.setCodec( "UTF-8" );
> t << s;
> f.close();
> }
> I can open out.txt in notepad and all the non-ascii chars are fine.
>
> But I can't get it to work on Mac OS X. If I preview the contents of the
> file in Finder or display the file contents in TextEdit.app the
> non-ascii chars are garbage (but they look fine if I write them to a
> HTML file with content set to UTF-8).
I have since found that if I change:
QTextStream t( &f );
t.setCodec( "UTF-8" );
To:
Q3TextStream t( &f );
t.setEncoding( Q3TextStream::unicode );
It now works fine on Mac. I don't really want to go back to Qt 3
classes. Does anyone know the Qt 4 equivalent of
Q3TextStream::setEncoding( Q3TextStream::unicode ) ?
QTextStream::setCodec( "UTF-8" ) and QTextStream::setCodec( "UTF-16" )
don't seem to work.
best regards
Andy Brice
http://www.perfecttableplan.com
http://www.successfulsoftware.net
--
[ signature omitted ]