[odb-users] Problem with QDate and Sqlite when it's mapped with TEXT type

علی دانش adanesh at noornet.net
Sat Sep 12 00:09:09 EDT 2015


Hi Boris,
Very good point! Using QLocate::c() static function, the problem of the proposed fix can be solved.

std::string s(QLocale::c().toString(v, "yyyy-MM-dd").toLatin1().constData());

Best regards,
Ali

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Thursday, September 10, 2015 7:02 PM
To: علی دانش
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Problem with QDate and Sqlite when it's mapped with TEXT type

Hi Ali,

> The problem is related to my operating system locale, because Qt uses 
> operating system locale. My OS locale is Persian.
> 
> odb\qt\date-time\sqlite\qdate-traits.hxx, Line 64:
> 
> std::string s (v.toString ("yyyy-MM-dd").toLatin1 ().constData ());
> 
> must be changed to:
> 
> std::string s(QLocale(QLocale::English).toString(v, 
> "yyyy-MM-dd").toLatin1().constData());

Thanks for tracking it down. The problem with the proposed fix is that locales are quite heavy-weight. I am not 100% sure about Qt but standard ones are. So I am not sure it would make sense to impose this overhead on cases where it is not necessary, which is probably 99% of all of them.

We have the same issue with using stringstream to parse integers, etc. When we switch to C++11, the plan is to use to_string()/sto*() instead which always use "C" locale. I wonder if there is a similar, locale-independent Date/Time parsing support in Qt?

Boris



More information about the odb-users mailing list