Qt.locale() always returns the 'C' locale.
authorMartin Jones <martin.jones@nokia.com>
Tue, 20 Dec 2011 01:02:10 +0000 (11:02 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 20 Dec 2011 05:37:53 +0000 (06:37 +0100)
QLocale(QString()) does not return the default locale.  If no
locale is specified, use the QLocale() constructor.

Change-Id: I76198b7ea66a6326483ec47ac36e080159ca459a
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/declarative/qml/qdeclarativelocale.cpp
tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp

index ae57edb..9f2116f 100644 (file)
@@ -811,7 +811,10 @@ v8::Handle<v8::Value> QDeclarativeLocale::locale(QV8Engine *v8engine, const QStr
     QV8LocaleDataDeletable *d = localeV8Data(v8engine);
     v8::Local<v8::Object> v8Value = d->constructor->NewInstance();
     QV8LocaleDataResource *r = new QV8LocaleDataResource(v8engine);
-    r->locale = QLocale(locale);
+    if (locale.isEmpty())
+        r->locale = QLocale();
+    else
+        r->locale = QLocale(locale);
     v8Value->SetExternalResource(r);
 
     return v8Value;
index b2f35fd..d49122c 100644 (file)
@@ -54,6 +54,8 @@ public:
     tst_qdeclarativelocale() { }
 
 private slots:
+    void defaultLocale();
+
     void properties_data();
     void properties();
     void currencySymbol_data();
@@ -114,6 +116,16 @@ private:
     QDeclarativeEngine engine;
 };
 
+void tst_qdeclarativelocale::defaultLocale()
+{
+    QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("properties.qml")));
+
+    QObject *obj = c.create();
+    QVERIFY(obj);
+
+    QCOMPARE(obj->property("name").toString(), QLocale().name());
+}
+
 #define LOCALE_PROP(type,prop) { #prop, QVariant(type(qlocale.prop())) }
 
 void tst_qdeclarativelocale::addPropertyData(const QString &l)