diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-10-07 14:22:14 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-10-07 23:20:26 +0000 |
commit | 9fcc259bc26d146538159700c719247edfa18bd4 (patch) | |
tree | 79cb2909af1e0e678359eb3bc18630889ab83051 /src | |
parent | f51652594cdcfdbc72d1ea5cc6f9b92bfc6df49a (diff) |
QJSEngine: Make uiLanguage a QObjectBindableProperty
It was a plain QProperty before. Given that the property is exposed in
the global Qt object in the engine, this could be problematic as with
the QProperty it is possible to change the value without emitting the
uiLanguageChanged signal. By using QObjectBindableProperty, we ensure
that the signal is always emitted.
Change-Id: I0f771a4e4d752704f469de27617835260b261052
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit d39efefe0d36a7da766246363788fc4d0c9971bf)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsapi/qjsengine.cpp | 8 | ||||
-rw-r--r-- | src/qml/jsapi/qjsengine_p.h | 4 |
2 files changed, 4 insertions, 8 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index a61e2829eb..2c6c579e4f 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -1105,13 +1105,9 @@ QJSValue QJSEngine::catchError() after installing translators in your application. By convention, an empty string means no translation from the language used in the source code is intended to occur. */ -void QJSEngine::setUiLanguage(const QString &language) -{ +void QJSEngine::setUiLanguage(const QString &language) { Q_D(QJSEngine); - if (language == d->uiLanguage) - return; - d->uiLanguage = language; - emit uiLanguageChanged(); + d->uiLanguage = language; // property takes care of signal emission if necessary } QString QJSEngine::uiLanguage() const diff --git a/src/qml/jsapi/qjsengine_p.h b/src/qml/jsapi/qjsengine_p.h index fb88781852..aa846bb246 100644 --- a/src/qml/jsapi/qjsengine_p.h +++ b/src/qml/jsapi/qjsengine_p.h @@ -107,8 +107,8 @@ public: // Shared by QQmlEngine mutable QRecursiveMutex mutex; - - QProperty<QString> uiLanguage; + void uiLanguageChanged() { Q_Q(QJSEngine); if (q) q->uiLanguageChanged(); } + Q_OBJECT_BINDABLE_PROPERTY(QJSEnginePrivate, QString, uiLanguage, &QJSEnginePrivate::uiLanguageChanged); // These methods may be called from the QML loader thread inline QQmlPropertyCache *cache(QObject *obj, QTypeRevision version = QTypeRevision(), bool doRef = false); |