Skip to content

Commit

Permalink
Remove QML engine ownership of InputContext
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
EddyTheCo authored and AndreaRicchi committed Oct 23, 2024
1 parent 7b96d76 commit 4dd2990
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/VirtualKeyboardInputContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "EnterKeyAction.hpp"
#include "EnterKeyActionAttachedType.hpp"
#include "InputPanelIface.hpp"
#include <QQmlEngine>

/**
* Private data class for VirtualKeyboardInputContext
Expand Down Expand Up @@ -45,12 +46,11 @@ VirtualKeyboardInputContext::VirtualKeyboardInputContext()
"CuteKeyboard", 1, 0, "InputEngine", inputEngineProvider);
connect(d->InputEngine, &DeclarativeInputEngine::animatingChanged, this,
&VirtualKeyboardInputContext::ensureFocusedObjectVisible);

qmlRegisterSingletonType<InputPanelIface>("CuteKeyboard", 1, 0,
"InputPanel", inputPanelProvider);

qmlRegisterSingletonType<InputPanelIface>(
qmlRegisterSingletonType<VirtualKeyboardInputContext>(
"CuteKeyboard", 1, 0, "InputContext", inputContextProvider);

qmlRegisterType<EnterKeyAction>("QtQuick.CuteKeyboard", 1, 0,
"EnterKeyAction");
qmlRegisterType<EnterKeyAction>("CuteKeyboard", 1, 0, "EnterKeyAction");
Expand Down Expand Up @@ -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;
}

0 comments on commit 4dd2990

Please sign in to comment.