[Interest] Question about setting QLocale
Thiago Macieira
thiago.macieira at intel.com
Mon Nov 30 18:53:13 CET 2015
On Monday 30 November 2015 17:43:27 Murphy, Sean wrote:
> This all works fine when a user logs a file and later reloads it on the same
> machine (or at least one set to the same locale). But if someone in China
> sends me a file they logged, my reader fails. The issue is the "ddd" in the
> QDateTime::toString() string format. According to the docs that does this:
> the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system
> locale to localize the name, i.e. QLocale::system(). And since
> QDateTime::fromString(data, "ddd MM/dd/yyyy hh:mm:ss.zzz") also uses system
> locale to localize the name, it fails to convert because what's been
> written in the file for data recorded on a Friday is "ÖÜÎå", but when I'm
> reading it on my US localized machine, fromString() expects to see "Fri",
> and I end up with an invalid QDateTime object.
That's a bug. And there's another bug in your reading/writing of the string,
but that's besides the point.
QString QDateTime::toString(const QString& format) const
{
return QLocale::system().toString(*this, format);
}
It should have been QLocale::c(). It's been like the above since 5.2.0 and no
one noticed. That is, btw, your workaround: use
QLocale::c().toString(ample.sampleTime(), "ddd MM/dd/yyyy HH:mm:ss.zzz")
Please file the issue too. I'm not sure we'll be able to change the behaviour
during 5.x, but we should be able to in 6.0.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list