[Interest] Question about setting QLocale
Murphy, Sean
smurphy at walbro.com
Mon Nov 30 19:58:53 CET 2015
Thanks for the quick reply, Thiago
> That's a bug. And there's another bug in your reading/writing of the string, but
> that's besides the point.
Can you go into more details about this? I'd prefer to have no bugs! ;)
> 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")
Is that really a bug in Qt though? I'd think as a developer/user in a non-English speaking country that if I were to write out a date object using either the "ddd" or "dddd" options, that I would expect those to show up in my native language. I just wrote a quick little test app, using German instead of Chinese, since I can't read Chinese at all:
main.cpp:
QApplication a(argc, argv);
QLocale::setDefault(QLocale(QLocale::German, QLocale::Germany));
MainWindow w;
w.show();
return a.exec();
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->dateTimeEdit, SIGNAL(dateTimeChanged(QDateTime)),
SLOT(slotUpdateText()));
slotUpdateText();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slotUpdateText()
{
QDateTime dt = ui->dateTimeEdit->dateTime();
ui->plainTextEdit->clear();
QString textString;
QLocale german(QLocale::German, QLocale::Germany);
QLocale defaultLocale;
textString += QString("DateTime: ") + dt.toString("dddd MM/dd/yyyy HH:mm:ss.zzz") + QString("\n");
textString += QString("Default: ") + defaultLocale.toString(dt, "dddd MM/dd/yyyy HH:mm:ss.zzz") + QString("\n");
textString += QString("C: ") + QLocale::c().toString(dt, "dddd MM/dd/yyyy HH:mm:ss.zzz") + QString("\n");
textString += QString("German: ") + german.toString(dt, "dddd MM/dd/yyyy HH:mm:ss.zzz") + QString("\n");
ui->plainTextEdit->setPlainText(textString);
}
This produces:
DateTime: Saturday 01/01/2000 00:00:00.000
Default: Samstag 01/01/2000 00:00:00.000
C: Saturday 01/01/2000 00:00:00.000
German: Samstag 01/01/2000 00:00:00.000
So I'd think your proposal to change QDateTime::toString() to use QLocale::c() would be the wrong behavior. If I'm in Germany, I'd expect to see Samstag, not Saturday. Or am I making some other mistake in my test application (or misunderstanding what QLocale::c() actually does)? I'm assuming that the line:
QLocale::setDefault(QLocale(QLocale::German, QLocale::Germany));
Fakes out the rest of the Qt classes to think I'm in Germany, although that first line I print out, where I use QDateTime::toString() and I'm getting it in English kind of says otherwise.
> 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.
Waiting to make sure I understand you correctly!
Sean
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qlocaleTest.zip
Type: application/x-zip-compressed
Size: 2384 bytes
Desc: qlocaleTest.zip
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151130/5c422f27/attachment.bin>
More information about the Interest
mailing list