diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2023-11-15 15:43:22 +0100 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2023-12-08 13:33:12 +0100 |
commit | 54260530836bdc4d189e7b69d75d2c070318f392 (patch) | |
tree | e9f7b428056c00b9cfb01be971af52df85340680 /tests/manual | |
parent | 65ba6092bb3526984a42e4b9fe34c1d5e9530142 (diff) |
qmlls: add manual test for automatic qmlls cmake type registration
Add a manual test for the CMake type registration, along with
instructions on what to test.
Task-number: QTBUG-118705
Change-Id: I36bb752fd255f9235f27dc382f8be477ff24a283
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/qmlls-cmake-builds/CMakeLists.txt | 40 | ||||
-rw-r--r-- | tests/manual/qmlls-cmake-builds/Main.qml | 14 | ||||
-rw-r--r-- | tests/manual/qmlls-cmake-builds/README.md | 16 | ||||
-rw-r--r-- | tests/manual/qmlls-cmake-builds/helloworld.cpp | 8 | ||||
-rw-r--r-- | tests/manual/qmlls-cmake-builds/helloworld.h | 29 | ||||
-rw-r--r-- | tests/manual/qmlls-cmake-builds/main.cpp | 22 |
6 files changed, 129 insertions, 0 deletions
diff --git a/tests/manual/qmlls-cmake-builds/CMakeLists.txt b/tests/manual/qmlls-cmake-builds/CMakeLists.txt new file mode 100644 index 0000000000..e9bf94e034 --- /dev/null +++ b/tests/manual/qmlls-cmake-builds/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(qmllscmakebuilds VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(QT_QML_GENERATE_QMLLS_INI ON CACHE BOOL "" FORCE) + +find_package(Qt6 REQUIRED COMPONENTS Quick) + +qt_standard_project_setup(REQUIRES 6.5) + +qt_add_executable(appautoGenCMake + main.cpp +) + +qt_add_qml_module(appautoGenCMake + URI AutoGenCMake + VERSION 1.0 + QML_FILES Main.qml + SOURCES helloworld.cpp helloworld.h +) + +# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. +# If you are developing for iOS or macOS you should consider setting an +# explicit, fixed bundle identifier manually though. +set_target_properties(appautoGenCMake PROPERTIES +# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appautoGenCMake + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +target_link_libraries(appautoGenCMake + PRIVATE Qt6::Quick +) diff --git a/tests/manual/qmlls-cmake-builds/Main.qml b/tests/manual/qmlls-cmake-builds/Main.qml new file mode 100644 index 0000000000..daecc7b35e --- /dev/null +++ b/tests/manual/qmlls-cmake-builds/Main.qml @@ -0,0 +1,14 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import autoGenCMake + +Window { + width: 640 + height: 480 + visible: true + title: qsTr("Hello World") + + HelloWorld { myP: 55; myPPP: 55 } +} diff --git a/tests/manual/qmlls-cmake-builds/README.md b/tests/manual/qmlls-cmake-builds/README.md new file mode 100644 index 0000000000..1063433f1d --- /dev/null +++ b/tests/manual/qmlls-cmake-builds/README.md @@ -0,0 +1,16 @@ +# Testing the automatic qmlls CMake type registration + +First of all, setup qmlls in your favorite editor (see https://www.qt.io/blog/whats-new-in-qml-language-server-qmlls-shipped-with-qt-6.6 for instructions). + +## Steps + +1. Open the manual test using the `CMakeLists.txt` (for QtC, for example) or the folder in which the `CMakeLists.txt` lies (for VS Code, for example) in the editor prepared for qmlls. +2. Make sure the project is configured. It does not need to be built, just configured via CMake. +3. In your editor, open the `Main.qml` and `helloworld.h`. +4. Modify the `helloworld.h` file by commenting the existing `Q_PROPERTY myPPP` out and save `helloworld.h`. +5. In the Main.qml file, write some code (add or delete a newline). It should complain about the binding to `myPPP` in +`HelloWorld`, as the property does not exist anymore. It should also not propose myPPP as autocompletion +in `HelloWorld` anymore. + +6. Repeat steps 4 + 5 with your own modifications and check that the modification in the `helloworld.h` can be seen in +the `Main.qml` file, without having to rebuild the project yourself. diff --git a/tests/manual/qmlls-cmake-builds/helloworld.cpp b/tests/manual/qmlls-cmake-builds/helloworld.cpp new file mode 100644 index 0000000000..00b3caceae --- /dev/null +++ b/tests/manual/qmlls-cmake-builds/helloworld.cpp @@ -0,0 +1,8 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "helloworld.h" + +HelloWorld::HelloWorld(QObject *parent) + : QObject{parent} +{} diff --git a/tests/manual/qmlls-cmake-builds/helloworld.h b/tests/manual/qmlls-cmake-builds/helloworld.h new file mode 100644 index 0000000000..a7709b5acd --- /dev/null +++ b/tests/manual/qmlls-cmake-builds/helloworld.h @@ -0,0 +1,29 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef HELLOWORLD_H +#define HELLOWORLD_H + +#include <QObject> +#include <QQmlEngine> + +class HelloWorld : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int myP READ myP WRITE setMyP NOTIFY myPChanged FINAL) + Q_PROPERTY(int myPPP READ myP WRITE setMyP NOTIFY myPChanged FINAL) + +public: + explicit HelloWorld(QObject *parent = nullptr); + + int myP() { return m_myP; } + void setMyP(int p) { m_myP = p; } +private: + int m_myP; + +signals: + void myPChanged(); +}; + +#endif // HELLOWORLD_H diff --git a/tests/manual/qmlls-cmake-builds/main.cpp b/tests/manual/qmlls-cmake-builds/main.cpp new file mode 100644 index 0000000000..3b0c49c334 --- /dev/null +++ b/tests/manual/qmlls-cmake-builds/main.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + const QUrl url(u"qrc:/autoGenCMake/Main.qml"_qs); + QObject::connect( + &engine, + &QQmlApplicationEngine::objectCreationFailed, + &app, + []() { QCoreApplication::exit(-1); }, + Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} |