From a0933e4fe69091f401e35c8d9640903f5acac21f Mon Sep 17 00:00:00 2001 From: Eduardo Gonzalez Date: Tue, 22 Oct 2024 12:10:36 +0200 Subject: [PATCH] Remove QML engine ownership of InputContext Set the ownership of the singleton object to cpp. The latter makes that the QML engine can not delete the instance. Fix #24. Signed-off-by: Eduardo Gonzalez --- src/VirtualKeyboardInputContext.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/VirtualKeyboardInputContext.cpp b/src/VirtualKeyboardInputContext.cpp index c8fe344..84b23c4 100644 --- a/src/VirtualKeyboardInputContext.cpp +++ b/src/VirtualKeyboardInputContext.cpp @@ -10,6 +10,7 @@ #include "EnterKeyAction.hpp" #include "EnterKeyActionAttachedType.hpp" #include "InputPanelIface.hpp" +#include /** * Private data class for VirtualKeyboardInputContext @@ -45,12 +46,11 @@ VirtualKeyboardInputContext::VirtualKeyboardInputContext() "CuteKeyboard", 1, 0, "InputEngine", inputEngineProvider); connect(d->InputEngine, &DeclarativeInputEngine::animatingChanged, this, &VirtualKeyboardInputContext::ensureFocusedObjectVisible); + qmlRegisterSingletonType("CuteKeyboard", 1, 0, "InputPanel", inputPanelProvider); - - qmlRegisterSingletonType( + qmlRegisterSingletonType( "CuteKeyboard", 1, 0, "InputContext", inputContextProvider); - qmlRegisterType("QtQuick.CuteKeyboard", 1, 0, "EnterKeyAction"); qmlRegisterType("CuteKeyboard", 1, 0, "EnterKeyAction"); @@ -217,5 +217,11 @@ QObject *VirtualKeyboardInputContext::inputContextProvider( QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) - return VirtualKeyboardInputContext::instance(); + const auto instance=VirtualKeyboardInputContext::instance(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QQmlEngine::setObjectOwnership(instance, QQmlEngine::CppOwnership); +#else + QJSEngine::setObjectOwnership(instance,QJSEngine::CppOwnership); +#endif + return instance; }