diff --git a/src/plugins/platforms/wasm/qwasminputcontext.cpp b/src/plugins/platforms/wasm/qwasminputcontext.cpp index 76328aa6db8..a5e54d9c7b8 100644 --- a/src/plugins/platforms/wasm/qwasminputcontext.cpp +++ b/src/plugins/platforms/wasm/qwasminputcontext.cpp @@ -327,8 +327,8 @@ void QWasmInputContext::updateInputElement() m_inputElement.set("value", ""); m_inputElement.call("blur"); - if (focusWindow && focusWindow->handle()) - ((QWasmWindow *)(focusWindow->handle()))->focus(); + if (QWasmWindow *wasmwindow = QWasmWindow::fromWindow(focusWindow)) + wasmwindow->focus(); return; } diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index 1bfcd75e3f4..83a4689fc1b 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -211,8 +211,10 @@ QSurfaceFormat QWasmWindow::format() const return window()->requestedFormat(); } -QWasmWindow *QWasmWindow::fromWindow(QWindow *window) +QWasmWindow *QWasmWindow::fromWindow(const QWindow *window) { + if (!window ||!window->handle()) + return nullptr; return static_cast(window->handle()); } diff --git a/src/plugins/platforms/wasm/qwasmwindow.h b/src/plugins/platforms/wasm/qwasmwindow.h index 3dcf8bd894c..be424753d3f 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.h +++ b/src/plugins/platforms/wasm/qwasmwindow.h @@ -45,7 +45,7 @@ public: QWasmBackingStore *backingStore, WId nativeHandle); ~QWasmWindow() final; - static QWasmWindow *fromWindow(QWindow *window); + static QWasmWindow *fromWindow(const QWindow *window); QSurfaceFormat format() const override; void registerEventHandlers();