Hi,
I'm confused with the QtPropertyBrowser and localization.
My system is:
MS Windows 7 Home Premium SP1 (german),
Qt 4.8.0
Qt Creator 2.4.0,
Qt PropertyBrowser 2.6 (Qt-Solution)
MS Visual Studio 2008 Version 9.0.30729.1 SP
First of all, is it true if I set the system property with LANG(EN)
(http://lists.trolltech.com/qt-interest/2008-02/msg00737.html)
then the QLocale::system change to it?
I have downloaded the QtPropertyBrowser framework:
http://qt.gitorious.org/qt-solutions/qt-solutions/trees/master/qtpropertybrowser
I build it and run the extension example.
There is a PointF property and I can change the Point X and Y values
(both are double properties).
When I remove the system property LANG, I have as system properties
(QLocale::system()) de_DE.
I restart the Qt Creator and run the example. Everything is ok, I have
the german comma (displayed
and in the editor). But when I set the system property LANG with EN,
restart the Qt Creator and the
example, I get the german comma again. A qDebug with QLocale::system()
show me en_US.
Have I something doing wrong?
I searched in the source code of the propertybrowser and found in the class
propertymanager.cpp the function (about line 1056):
/*!
\reimp
*/
QString QtDoublePropertyManager::valueText(const QtProperty *property) const
{
const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it =
d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
return QLocale::system().toString(it.value().val, 'f',
it.value().decimals);
}
My modification is:
/*!
\reimp
*/
QString QtDoublePropertyManager::valueText(const QtProperty *property) const
{
const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it =
d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
QLocale l;
qDebug() << Q_FUNC_INFO << "System:" << QLocale::system().name();
qDebug() << Q_FUNC_INFO << "System country:" <<
QLocale::countryToString(QLocale::system().country());
qDebug() << Q_FUNC_INFO << "System language:" <<
QLocale::languageToString(QLocale::system().language());
qDebug() << Q_FUNC_INFO << "l (QLocale):" << l.name();
qDebug() << Q_FUNC_INFO << "Original (System):" <<
QLocale::system().toString(it.value().val, 'f', it.value().decimals);
qDebug() << Q_FUNC_INFO << "Return (l):" <<
l.toString(it.value().val, 'f', it.value().decimals);
return l.toString(it.value().val, 'f', it.value().decimals);
//return QLocale::system().toString(it.value().val, 'f',
it.value().decimals);
}
Application output:
class QString __thiscall QtDoublePropertyManager::valueText(const class QtProperty *)
const System: "en_US"
class QString __thiscall QtDoublePropertyManager::valueText(const class
QtProperty *) const System country: "UnitedStates"
class QString __thiscall QtDoublePropertyManager::valueText(const class
QtProperty *) const System language: "English"
class QString __thiscall QtDoublePropertyManager::valueText(const class
QtProperty *) const l (QLocale): "en_US"
class QString __thiscall QtDoublePropertyManager::valueText(const class
QtProperty *) const Original (System): "2,50"
class QString __thiscall QtDoublePropertyManager::valueText(const class
QtProperty *) const Return (l): "2,50"
I think there is a bug possible, because when I set no default locale (the
system locale is valid)
I have the result described above (I get every time the german comma, but have
en_US).
If I set in the main.cpp of the example a default locale
QLocale::setDefault(QLocale(QLocale::English,QLocale::UnitedStates));
my modification works, I get a decimal point.
The same behavior is in the function (line 2909):
/*!
\reimp
*/
QString QtPointFPropertyManager::valueText(const QtProperty *property) const
{
const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it =
d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
const QPointF v = it.value().val;
const int dec = it.value().decimals;
return QString(tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
.arg(QString::number(v.y(), 'f', dec)));
}
My modification:
QStringQtPointFPropertyManager::valueText(constQtProperty*property)const
{
const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it =
d_ptr->m_values.constFind(property);
if (it == d_ptr->m_values.constEnd())
return QString();
const QPointF v = it.value().val;
const int dec = it.value().decimals;
QLocale l;
return QString(tr("(%1, %2)").arg(l.toString(v.x(), 'f', dec))
.arg(l.toString(v.y(), 'f', dec)));
// return QString(tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
// .arg(QString::number(v.y(), 'f', dec)));
}
Please have a look at the Qt Designer
(...Qt\4.8.0\tools\shared\qtpropertybrowser\qtpropertymanager.cpp, line
1037),
there is with the german comma something wrong too, I think.
But I want to wait for some answers here, before I make a new post for
the Designer.
Thomas Meyer
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest