[Qt-interest] Non-latin characters in QString and char * on Windows

Donal O'Connor donaloconnor at gmail.com
Wed Mar 2 22:26:25 CET 2011


Correct me if I'm wrong but surely const char * fileNameStr will be pointing
to an invalid part of memory.

fileName.toLocal8Bit() creates a temp object in which you are
calling constData() on. Soon as the expression ends, the temp object
toLocal8Bit() has created is destroyed.

Donal


On Wed, Mar 2, 2011 at 8:05 PM, Konstantin Tokarev <annulen at yandex.ru>wrote:

> Hi all,
>
> I need to convert QString, containg non-latin characters (specifically,
> cyrillic) to const char *,
> in order to open file with ifstream (requirement of 3rd party library). One
> may think that it's
> about QString::toLocal8Bit(), but it does not help on Windows!
>
> See attached program. On Linux with UTF-8 everything works fine with either
> toUtf8 or
> toLocal8Bit. On Windows (default encoding is CP1251) both functions return
> crap (different
> between each other). Of course, ifstream cannot open corrupted file paths.
>
> How to get proper representation of QString fileName in const char * ?
>
> --
> Regards,
> Konstantin
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110302/d542e59f/attachment.html 


More information about the Qt-interest-old mailing list