[Interest] Question about setting QLocale
Thiago Macieira
thiago.macieira at intel.com
Tue Dec 1 21:15:53 CET 2015
On Tuesday 01 December 2015 18:15:42 Murphy, Sean wrote:
> Also, in this discussion we've had, we've focused exclusively on the
> behavior of QDate/QDateTime classes, which live in QtCore. If you make your
> change, what happens with QDateEdit/QDateTimeEdit in QtGUI?
QtGui discussion is separate. QWidget, in specific, has a locale() member,
which by default is the same as a default-constructed QLocale. The default
QLocale is the same as QLocale::system(), unless you called setDefault().
> Right now,
> unless I'm overlooking something, QDateTimeEdit only has the following
> function for setting the display format: void QDateTimeEdit
> ::setDisplayFormat(const QString & format)
And QWidget::setLocale().
> ui->dateTimeEdit->setDisplayFormat("dddd dd.MM.yyyy HH:mm:ss.zzz");
> ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime()); // widget now
> shows "Dienstag 01.12.2015 10:57:48.164"
> qDebug() <<
> ui->dateTimeEdit->dateTime().toString("dddd dd.MM.yyyy HH:mm:ss.zzz "); //
> where QDateTime::toString() is now using your fix, QLocale::c()...
>
> The debug statement would print out "Tuesday 01.12.2015 10:57:48.164". Well
> this certainly seems like unexpected behavior - in both spots I used the
> exact same formatting string and I got two different results...
>From my point of view, that would be the expected behaviour. Users don't read
debugging statements, developers do. I want to get the debugging information
in a language I can read. If it printed "一", "二" or "三", I wouldn't be able to
do my job and understand whether the code is working properly.
> Unless
> you're saying that with your fix the widget would have also said "Tuesday
> 01.12.2015 10:57:48.164" because QDateTimeEdit::setDateTime() would also
> use QLocale::c() to populate the widget?
It uses QWidget::locale(). The change to QDateTime would not affect it.
> But again that seems very weird,
> my locale is German/Germany, so I'd expect to see the "dddd" portion
> represented as "Dienstag", not "Tuesday". Regardless of whether it's in a
> widget or written out to a file.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list