From 5344bf1619e7ec9c39ec1d9c18e813305426728c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 2 Jun 2016 15:25:31 +0200 Subject: [PATCH] [plugins/qpa] Handle case that qtvirtualkeyboard plugin is not available more gracefully We didn't check whether creating the QPlatfromInputContext worked and accessed the m_inputContext unconditionally which obviously crashed. Now the connects related to QInputMethods are not setup if we failed to create the QPlatfromInputContext. Reviewed-By: bshah --- plugins/qpa/integration.cpp | 44 +++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/plugins/qpa/integration.cpp b/plugins/qpa/integration.cpp index 41b47eeeef..90802e59a7 100644 --- a/plugins/qpa/integration.cpp +++ b/plugins/qpa/integration.cpp @@ -97,29 +97,31 @@ void Integration::initialize() screenAdded(m_dummyScreen); m_inputContext.reset(QPlatformInputContextFactory::create(QStringLiteral("qtvirtualkeyboard"))); qunsetenv("QT_IM_MODULE"); - connect(qApp, &QGuiApplication::focusObjectChanged, this, - [this] { - if (VirtualKeyboard::self() && qApp->focusObject() != VirtualKeyboard::self()) { - m_inputContext->setFocusObject(VirtualKeyboard::self()); - } - } - ); - connect(kwinApp(), &Application::workspaceCreated, this, - [this] { - if (VirtualKeyboard::self()) { - m_inputContext->setFocusObject(VirtualKeyboard::self()); - } - } - ); - connect(qApp->inputMethod(), &QInputMethod::visibleChanged, this, - [this] { - if (qApp->inputMethod()->isVisible()) { - if (QWindow *w = VirtualKeyboard::self()->inputPanel()) { - QWindowSystemInterface::handleWindowActivated(w, Qt::ActiveWindowFocusReason); + if (!m_inputContext.isNull()) { + connect(qApp, &QGuiApplication::focusObjectChanged, this, + [this] { + if (VirtualKeyboard::self() && qApp->focusObject() != VirtualKeyboard::self()) { + m_inputContext->setFocusObject(VirtualKeyboard::self()); } } - } - ); + ); + connect(kwinApp(), &Application::workspaceCreated, this, + [this] { + if (VirtualKeyboard::self()) { + m_inputContext->setFocusObject(VirtualKeyboard::self()); + } + } + ); + connect(qApp->inputMethod(), &QInputMethod::visibleChanged, this, + [this] { + if (qApp->inputMethod()->isVisible()) { + if (QWindow *w = VirtualKeyboard::self()->inputPanel()) { + QWindowSystemInterface::handleWindowActivated(w, Qt::ActiveWindowFocusReason); + } + } + } + ); + } } QAbstractEventDispatcher *Integration::createEventDispatcher() const