Discussion:
File::encodeName() and Utf8 as the default encoding under Qt5
Lubomir I. Ivanov
2014-10-29 15:32:58 UTC
Permalink
hi Thiogo,

related to bug #740
where special chars in Win32 file names no longer work (again).

in mainwindow.cpp we have some ::encodeName() calls.
as i understand it on Qt4 it should work because of the setup in qt-qui.cpp.

but for Qt5:

http://qt-project.org/doc/qt-5/sourcebreaks.html:

QFile::setEncodingFunction() and QFile::setDecodingFunction() are
deprecated. The QFile::encodeName() andQFile::decodeName() functions
are now hard-coded to operate on QString::fromLocal8Bit() and
QString::toLocal8Bit() only. The old behavior is still possible using
QTextCodec::setCodecForLocale(), but it is recommended that the new
code should not make assumptions about the file system encoding and
older code should remove such assumptions.

now, i know how to fix the issue by simply not use File::encodeName()
at all on Win32 and use QString::toUtf8() instead but is there a
cleaner way with no #ifdefs?

not sure if QTextCodec::setCodecForLocale() should be set to Utf8 on Win32...

lubomir
--
Lubomir I. Ivanov
2014-10-29 15:33:29 UTC
Permalink
Post by Lubomir I. Ivanov
hi Thiogo,
oops sorry - typo (Thiago).

lubomir
--
Thiago Macieira
2014-10-29 16:02:59 UTC
Permalink
Post by Lubomir I. Ivanov
now, i know how to fix the issue by simply not use File::encodeName()
at all on Win32 and use QString::toUtf8() instead but is there a
cleaner way with no #ifdefs?
not sure if QTextCodec::setCodecForLocale() should be set to Utf8 on Win32...
Hmm... I'm not sure what will happen if you setCodecForLocale on Windows, I've
never tried.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
Lubomir I. Ivanov
2014-10-29 16:18:14 UTC
Permalink
Post by Thiago Macieira
Post by Lubomir I. Ivanov
now, i know how to fix the issue by simply not use File::encodeName()
at all on Win32 and use QString::toUtf8() instead but is there a
cleaner way with no #ifdefs?
not sure if QTextCodec::setCodecForLocale() should be set to Utf8 on Win32...
Hmm... I'm not sure what will happen if you setCodecForLocale on Windows, I've
never tried.
just tried setting it to UTF-8 and the filenames work again
(QFile::encodeName()).
but i really have no idea of the more global consequences of this. if
it breaks other important areas perhaps the attached patch should not
be applied.

lubomir
--
Dirk Hohndel
2014-10-29 16:27:52 UTC
Permalink
Post by Lubomir I. Ivanov
Post by Thiago Macieira
Post by Lubomir I. Ivanov
now, i know how to fix the issue by simply not use File::encodeName()
at all on Win32 and use QString::toUtf8() instead but is there a
cleaner way with no #ifdefs?
not sure if QTextCodec::setCodecForLocale() should be set to Utf8 on Win32...
Hmm... I'm not sure what will happen if you setCodecForLocale on Windows, I've
never tried.
just tried setting it to UTF-8 and the filenames work again
(QFile::encodeName()).
but i really have no idea of the more global consequences of this. if
it breaks other important areas perhaps the attached patch should not
be applied.
Well, you and Thiago are the experts I look at when it comes to these
things... what do we have to test to make sure this doesn't break things?

We have a ton of Windows users on this mailing list, so as long as we know
what to test this should be easy, I can make a new test binary in a
heartbeat... :-)

/D
Lubomir I. Ivanov
2014-10-29 17:04:20 UTC
Permalink
Post by Dirk Hohndel
Post by Lubomir I. Ivanov
Post by Thiago Macieira
Post by Lubomir I. Ivanov
now, i know how to fix the issue by simply not use File::encodeName()
at all on Win32 and use QString::toUtf8() instead but is there a
cleaner way with no #ifdefs?
not sure if QTextCodec::setCodecForLocale() should be set to Utf8 on Win32...
Hmm... I'm not sure what will happen if you setCodecForLocale on Windows, I've
never tried.
just tried setting it to UTF-8 and the filenames work again
(QFile::encodeName()).
but i really have no idea of the more global consequences of this. if
it breaks other important areas perhaps the attached patch should not
be applied.
Well, you and Thiago are the experts I look at when it comes to these
things... what do we have to test to make sure this doesn't break things?
We have a ton of Windows users on this mailing list, so as long as we know
what to test this should be easy, I can make a new test binary in a
heartbeat... :-)
i've browsed the Qt5 source for a while and it looks like that the
change affects QString::toLocal8Bit(), so i've tried some of the areas
where toLocal8Bit() is used in the app (Win32):

- cmd arguments: no problem (with special chars in filenames to open even)
- webservices: can't test it - says "INTERNAL_SERVER_ERROR"

i must admit that the whole concept locale codecs evades me a little...
unless Thiago is against this one and there are other Qt areas where
codecForLocale() is important, the patch works (tm).

lubomir
--
Dirk Hohndel
2014-10-29 18:33:49 UTC
Permalink
Post by Lubomir I. Ivanov
change affects QString::toLocal8Bit(), so i've tried some of the areas
- cmd arguments: no problem (with special chars in filenames to open even)
- webservices: can't test it - says "INTERNAL_SERVER_ERROR"
Umm? What were you trying to do. I'm not aware of that server being
down...

/D
Lubomir I. Ivanov
2014-10-29 18:36:47 UTC
Permalink
Post by Dirk Hohndel
Post by Lubomir I. Ivanov
change affects QString::toLocal8Bit(), so i've tried some of the areas
- cmd arguments: no problem (with special chars in filenames to open even)
- webservices: can't test it - says "INTERNAL_SERVER_ERROR"
Umm? What were you trying to do. I'm not aware of that server being
down...
bad ID, it works.

lubomir
--
Thiago Macieira
2014-10-29 18:39:49 UTC
Permalink
Post by Lubomir I. Ivanov
i must admit that the whole concept locale codecs evades me a little...
unless Thiago is against this one and there are other Qt areas where
codecForLocale() is important, the patch works (tm).
Qt itself always uses the wide-char functions of the Win32 API, so it should
not be affected by the locale choice. It will affect only the defaults in
QTextStream and other string conversion functions, but I'm guessing we *want*
to read and write UTF-8 to our files anyway.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
Loading...