diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-01-10 12:56:58 +0100 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2023-01-18 14:29:47 +0000 |
| commit | 281497bfbc6af36c2051d255eed350c03da74439 (patch) | |
| tree | 3cd8ada9860f433f0b4f1215bda9c166d97cccee /src | |
| parent | 19b35008e2b2bebef10a9d52c8389920df1e1953 (diff) | |
Fix minor API problems
Add explicit where appropriate, and use more elegant constructs in
inline functions. Introduce removed_api.cpp for
QJSEngine::create(int, const void *).
Pick-to: 6.5
Change-Id: Ie54b0494fe3c5567f8a5ca361c3a583de3d97dd5
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/qml/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/qml/compat/removed_api.cpp | 21 | ||||
| -rw-r--r-- | src/qml/jsapi/qjsengine.cpp | 8 | ||||
| -rw-r--r-- | src/qml/jsapi/qjsengine.h | 23 | ||||
| -rw-r--r-- | src/qml/qml/qqmlapplicationengine.h | 3 | ||||
| -rw-r--r-- | src/qml/qml/qqmlcomponent.h | 4 |
6 files changed, 36 insertions, 26 deletions
diff --git a/src/qml/CMakeLists.txt b/src/qml/CMakeLists.txt index 5296494bd8..b08319090b 100644 --- a/src/qml/CMakeLists.txt +++ b/src/qml/CMakeLists.txt @@ -128,6 +128,7 @@ qt_internal_add_qml_module(Qml common/qv4staticvalue_p.h common/qv4stringtoarrayindex_p.h common/qqmltranslation.cpp common/qqmltranslation_p.h + compat/removed_api.cpp compiler/qqmlirbuilder.cpp compiler/qqmlirbuilder_p.h compiler/qv4bytecodegenerator.cpp compiler/qv4bytecodegenerator_p.h compiler/qv4bytecodehandler.cpp compiler/qv4bytecodehandler_p.h @@ -421,6 +422,8 @@ qt_internal_add_qml_module(Qml GENERATE_PRIVATE_CPP_EXPORTS ) +qt_update_ignore_pch_source(Qml "compat/removed_api.cpp") + qt_internal_add_qml_module(QmlMeta URI "QtQml" VERSION "${PROJECT_VERSION}" diff --git a/src/qml/compat/removed_api.cpp b/src/qml/compat/removed_api.cpp new file mode 100644 index 0000000000..acdd0bab13 --- /dev/null +++ b/src/qml/compat/removed_api.cpp @@ -0,0 +1,21 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#define QT_QML_BUILD_REMOVED_API + +#include "qtqmlglobal.h" + +QT_USE_NAMESPACE + +#if QT_QML_REMOVED_SINCE(6, 5) + +#include <QtQml/qjsengine.h> + +QJSValue QJSEngine::create(int typeId, const void *ptr) +{ + QMetaType type(typeId); + return create(type, ptr); +} + +#endif + diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index add8626691..04edd7a684 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -818,14 +818,6 @@ QJSValue QJSEngine::create(QMetaType type, const void *ptr) return QJSValuePrivate::fromReturnedValue(v->asReturnedValue()); } -#if QT_VERSION < QT_VERSION_CHECK(7,0,0) -QJSValue QJSEngine::create(int typeId, const void *ptr) -{ - QMetaType type(typeId); - return create(type, ptr); -} -#endif - bool QJSEngine::convertPrimitive(const QJSPrimitiveValue &value, QMetaType type, void *ptr) { switch (value.type()) { diff --git a/src/qml/jsapi/qjsengine.h b/src/qml/jsapi/qjsengine.h index 11f1788701..9fb56f8cb8 100644 --- a/src/qml/jsapi/qjsengine.h +++ b/src/qml/jsapi/qjsengine.h @@ -76,9 +76,9 @@ public: std::is_same<T, double>, std::is_same<T, QString>>) { return QJSPrimitiveValue(value); + } else { + return createPrimitive(QMetaType::fromType<T>(), &value); } - - return createPrimitive(QMetaType::fromType<T>(), &value); } template <typename T> @@ -298,7 +298,7 @@ private: QJSPrimitiveValue createPrimitive(QMetaType type, const void *ptr); QJSManagedValue createManaged(QMetaType type, const void *ptr); QJSValue create(QMetaType type, const void *ptr); -#if QT_VERSION < QT_VERSION_CHECK(7,0,0) +#if QT_QML_REMOVED_SINCE(6, 5) QJSValue create(int id, const void *ptr); // only there for BC reasons #endif @@ -341,8 +341,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QJSEngine::Extensions) template<typename T> T qjsvalue_cast(const QJSValue &value) { - T t; - if (QJSEngine::convertV2(value, QMetaType::fromType<T>(), &t)) + if (T t; QJSEngine::convertV2(value, QMetaType::fromType<T>(), &t)) return t; else if (value.isVariant()) return qvariant_cast<T>(value.toVariant()); @@ -353,11 +352,8 @@ T qjsvalue_cast(const QJSValue &value) template<typename T> T qjsvalue_cast(const QJSManagedValue &value) { - { - T t; - if (QJSEngine::convertManaged(value, QMetaType::fromType<T>(), &t)) - return t; - } + if (T t; QJSEngine::convertManaged(value, QMetaType::fromType<T>(), &t)) + return t; return qvariant_cast<T>(value.toVariant()); } @@ -365,11 +361,8 @@ T qjsvalue_cast(const QJSManagedValue &value) template<typename T> T qjsvalue_cast(const QJSPrimitiveValue &value) { - { - T t; - if (QJSEngine::convertPrimitive(value, QMetaType::fromType<T>(), &t)) - return t; - } + if (T t; QJSEngine::convertPrimitive(value, QMetaType::fromType<T>(), &t)) + return t; return qvariant_cast<T>(value.toVariant()); } diff --git a/src/qml/qml/qqmlapplicationengine.h b/src/qml/qml/qqmlapplicationengine.h index afbb76dd06..69e4a7261c 100644 --- a/src/qml/qml/qqmlapplicationengine.h +++ b/src/qml/qml/qqmlapplicationengine.h @@ -19,7 +19,8 @@ class Q_QML_EXPORT QQmlApplicationEngine : public QQmlEngine public: QQmlApplicationEngine(QObject *parent = nullptr); QQmlApplicationEngine(const QUrl &url, QObject *parent = nullptr); - QQmlApplicationEngine(QAnyStringView uri, QAnyStringView typeName, QObject *parent = nullptr); + explicit QQmlApplicationEngine(QAnyStringView uri, QAnyStringView typeName, + QObject *parent = nullptr); QQmlApplicationEngine(const QString &filePath, QObject *parent = nullptr); ~QQmlApplicationEngine() override; diff --git a/src/qml/qml/qqmlcomponent.h b/src/qml/qml/qqmlcomponent.h index daa95df135..0c7f7ce1ff 100644 --- a/src/qml/qml/qqmlcomponent.h +++ b/src/qml/qml/qqmlcomponent.h @@ -53,8 +53,8 @@ public: QQmlComponent(QQmlEngine *, const QUrl &url, QObject *parent = nullptr); QQmlComponent(QQmlEngine *, const QUrl &url, CompilationMode mode, QObject *parent = nullptr); - QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, QObject *parent = nullptr); - QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, CompilationMode mode, QObject *parent = nullptr); + explicit QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, QObject *parent = nullptr); + explicit QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, CompilationMode mode, QObject *parent = nullptr); ~QQmlComponent() override; |
