From ebdb9105dd0508c95393488c42a103c46ba895c4 Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Wed, 24 Jun 2026 07:54:17 +0200 Subject: [PATCH] Add QJSEngine and ownership method Needed for https://github.com/JuliaGraphics/QML.jl/issues/218 --- CMakeLists.txt | 2 +- wrap_qml.hpp | 3 ++- wrap_qml_part_a.cpp | 1 + wrap_qml_part_b.cpp | 15 ++++++++++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e17cef9..f22450b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16.0) project(JlQML) -set(JlQML_VERSION 0.10.2) +set(JlQML_VERSION 0.10.3) message(STATUS "Project version: v${JlQML_VERSION}") set(CMAKE_MACOSX_RPATH 1) diff --git a/wrap_qml.hpp b/wrap_qml.hpp index 1459ae0..c71d1eb 100644 --- a/wrap_qml.hpp +++ b/wrap_qml.hpp @@ -41,7 +41,8 @@ template<> struct SuperType { using type = QObject; }; template<> struct SuperType { using type = QCoreApplication; }; template<> struct SuperType { using type = QObject; }; template<> struct SuperType { using type = QObject; }; -template<> struct SuperType { using type = QObject; }; +template<> struct SuperType { using type = QObject; }; +template<> struct SuperType { using type = QJSEngine; }; template<> struct SuperType { using type = QObject; }; template<> struct SuperType { using type = QQmlPropertyMap; }; template<> struct SuperType { using type = QQuickWindow; }; diff --git a/wrap_qml_part_a.cpp b/wrap_qml_part_a.cpp index be9e2cd..612defc 100644 --- a/wrap_qml_part_a.cpp +++ b/wrap_qml_part_a.cpp @@ -5,6 +5,7 @@ void wrap_part_a(jlcxx::Module& qml_module) using namespace jlcxx; qml_module.add_type("QObject") + .method("parent", &QObject::parent) .method("deleteLater", &QObject::deleteLater); qml_module.method("connect_destroyed_signal", [] (QObject& obj, jl_value_t* jl_f) { diff --git a/wrap_qml_part_b.cpp b/wrap_qml_part_b.cpp index 5dd81bb..7c0bcca 100644 --- a/wrap_qml_part_b.cpp +++ b/wrap_qml_part_b.cpp @@ -17,7 +17,20 @@ void wrap_part_b(jlcxx::Module& qml_module) qml_module.add_type("QQmlImageProviderBase", julia_base_type()); - qml_module.add_type("QQmlEngine", julia_base_type()) + qml_module.add_enum("ObjectOwnership", + std::vector({ + "CppOwnership", + "JavaScriptOwnership" + }), + std::vector({ + QJSEngine::CppOwnership, + QJSEngine::JavaScriptOwnership + }) + ); + + qml_module.add_type("QJSEngine", julia_base_type()); + qml_module.method("setObjectOwnership", QJSEngine::setObjectOwnership); + qml_module.add_type("QQmlEngine", julia_base_type()) .method("addImageProvider", &QQmlEngine::addImageProvider) .method("clearComponentCache", &QQmlEngine::clearComponentCache) .method("clearSingletons", &QQmlEngine::clearSingletons)