From 3df8eba0f5e9f9b0142914d53c1183c5a05030e7 Mon Sep 17 00:00:00 2001 From: Sami Shalayel Date: Wed, 21 Dec 2022 16:31:20 +0100 Subject: qmltc: generate code into namespaces Generate code into namespaces to avoid clashes between qmltc-generated and user code. Code generated by qmltc will by default be put in the URI_OF_MODULE namespace, and will generate subnamespaces to follow the module hierarchy if URI_OF_MODULE contains dots('.'). Also fix the test to use the new namespaces. [ChangeLog][Qml][qmltc] The type compiler will generate C++-code into a namespace by default. The new default namespace is inferred from the module's URI, where dots are interpreted as separating subnamespaces from each other, e.g., a type in module MyCompany.MyModule.Sub will be generated in the namespace MyCompany::MyModule::Sub. Fixes: QTBUG-109274 Change-Id: I3bfe2697b81e90bb63a079dc44c2810fc9925f97 Reviewed-by: Ulf Hermann Reviewed-by: Qt CI Bot --- src/qml/doc/snippets/qmltc/tst_qmltc_examples.cpp | 2 +- src/qml/doc/src/cmake/qt_add_qml_module.qdoc | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/qml/doc') diff --git a/src/qml/doc/snippets/qmltc/tst_qmltc_examples.cpp b/src/qml/doc/snippets/qmltc/tst_qmltc_examples.cpp index a78da416e2..7bda70f985 100644 --- a/src/qml/doc/snippets/qmltc/tst_qmltc_examples.cpp +++ b/src/qml/doc/snippets/qmltc/tst_qmltc_examples.cpp @@ -53,7 +53,7 @@ void tst_qmltc_examples::app() QQmlEngine e; QQuickWindow window; - QScopedPointer documentRoot(new myApp(&e)); + QScopedPointer documentRoot(new QmltcExample::myApp(&e)); documentRoot->setParentItem(window.contentItem()); window.setHeight(documentRoot->height()); diff --git a/src/qml/doc/src/cmake/qt_add_qml_module.qdoc b/src/qml/doc/src/cmake/qt_add_qml_module.qdoc index 9bef299970..7617d19033 100644 --- a/src/qml/doc/src/cmake/qt_add_qml_module.qdoc +++ b/src/qml/doc/src/cmake/qt_add_qml_module.qdoc @@ -655,4 +655,15 @@ with \l{QML Type Compiler}{qmltc}. Files with the source property C++ code resides. By default, no namespace is specified for user projects. The code generated from Qt's own sources is put under a QT_NAMESPACE namespace. +\c TYPE_COMPILER_NAMESPACE argument allows to override the namespace in which +\l{QML Type Compiler}{qmltc} generates code. +By default, the namespace of the generated code follows the module +hierarchy as depicted in the URI, +e.g., \c MyModule for a module with URI \c MyModule or +\c com::example::Module for URI \c com.example.MyModule. +By specifying the \c TYPE_COMPILER_NAMESPACE option, the generated code +can be put instead in a custom namespace, where different subnamespaces are to +be separated by a "::", e.g. "MyNamespace::MySubnamespace" for the namespace MySubnamespace that +is inside the MyNamespace. Apart from the "::", C++ namespace naming rules +apply. */ -- cgit v1.2.3