> Den 30-11-2015 kl. 18:43 skrev Murphy, Sean:
> > I'm having an issue with multiple locales in my application and I'm
> > trying to understand what the best fix should be. Our application is
> > being used in two places right now: China & the US. One of the
> > functions of the application is to log data samples to a csv file.
> > Another function is to be able to load that log file back in later to
> > look at the data.
> 
> I fix this problem by setting the locale temporarily to a known state before
> loading or saving files. This blog entry is about exactly this
> problem: http://www.vikingsoft.eu/blog/?p=21
> 
> I hope this helps,

Thanks Bo! I think in my case the answer will be to modify my application to 
write out the data using a standard, locale agnostic format, so I could either 
use the QLocale::c() version or using Qt::ISODate or Qt::RFC2822Date. That 
fixes the problem going forward - new files will have date/time information 
written out the same regardless of the user's locale. Technically the way I was 
logging data was poorly thought out to begin with since it in no way accounted 
for timezones, I was writing the date/time out in "ddd MM/dd/yyyy HH:mm:ss.zzz" 
format. So sure, you'd know that this sample was recorded on Monday, November 
30, 2015 at 13:52:19.428 in someone's local time, but you would have no idea in 
what time zone that was done. Using Qt::ISODate or Qt::RFC2822Date fixes that 
for me.

Once I make that change, I only have to deal with existing files that were 
recorded under the old format where the date portion was done as "ddd 
MM/dd/yyyy". For those, it's really only the "ddd" part that is locale 
dependent and is screwing me up. That is redundant data anyways since I have 
the day, month, and year data right after it. So the easiest fix is to read in 
the string, remove the first 4 characters (the "ddd " portion) and then use 
QDateTime::fromString(data, "MM/dd/yyyy HH:mm:ss.zzz") to read those in.

Sean
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to