Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-80357

Android platform plugin library must be modified to use Virtual Keyboard

    XMLWordPrintable

Details

    • Android
    •  6d6ca70538851e8334eb01550a93b60ceba75d34 (qt/qtbase/5.15)

    Description

      Brief summary: The Android platform plugin library does not contain the initialization code that is needed in order to load and use the Virtual Keyboard. The source has to be modified, and libqtforandroid.so rebuilt, in order for this to work.

      More detail: There appears to be an assumption that no Virtual Keyboard support is required for Android. The Qt install for Android does not include pre-built libraries and other supporting files for the Virtual Keyboard, such as are provided for Windows; and the Android platform plugin library is not set up to load the Virtual Keyboard (more details on that below). I can kind of understand why this assumption might be made, since Android has its own built-in OS soft keyboard (and other 3rd party keyboards are available). However, in our app, we have quite specific and specialized keyboard needs that the Android OS keyboard does not satisfy. We also want our users to see exactly the same soft keyboard in our Windows Tablet and Android apps. The Qt Virtual Keyboard is the ideal solution for this, so we really need to be able to use it on Android. And I doubt that we are the only Qt customers who would want the ability to use the Qt Virtual Keyboard on Android.

      The lack of pre-built libraries for Android is annoying, but not a big problem, as we were able to build those ourselves from source code.

      More problematic is the fact that the Android platform plugin library, libqtforandroid.so, does not contain the code that is needed to load the Virtual Keyboard and set it as the current QPlatformInputContext. This means that, even if you deploy the Virtual Keyboard libraries and set QT_IM_MODULE to "qtvirtualkeyboard", this is simply ignored and the Virtual Keyboard is not loaded or displayed.

      I was able to get this working by copying the relevant snippets of code from QWindowsIntegration (qwindowsintegration.h / .cpp) to QAndroidPlatformIntegration (qandroidplatformintegration.h / .cpp), and rebuilding libqtforandroid.so. Specifically, I had to make the following changes:

      • In the header file, declare an override for the initialize() function, and change the data member 'mutable QAndroidInputContext m_platformInputContext' to 'QScopedPointer<QPlatformInputContext> m_inputContext'.
      • In the cpp file, implement the initialize() function in a similar fashion to QWindowsIntegration::initialize():

      void QAndroidPlatformIntegration::initialize()
      {
          QString icStr = QPlatformInputContextFactory::requested();
          icStr.isNull() ? m_inputContext.reset(new QAndroidInputContext)
                         : m_inputContext.reset(QPlatformInputContextFactory::create(icStr));
      }

      • Modify the inputContext() function so that instead of returning '&m_platformInputContext', it returns 'm_inputContext.data()' (again, copied from QWindowsIntegration::inputContext()).

      I also had to add a #include for <QtGui/qpa/qplatforminputcontextfactory_p.h> to get this to compile.

      Having made these changes and got this to work, we are now faced with having to reapply these source code changes, and rebuild libqtforandroid.so, every time we move to a new release of Qt. We would really appreciate it if these changes could be applied to the "official" Qt sources. The changes should be low-risk, and harmless to anyone who is not using the Virtual Keyboard - but they will help to make it much easier for any other Qt users who wish to make use of this excellent tool on Android.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              assam Assam Boudjelthia
              roballan Rob Allan
              Santtu Ahonen Santtu Ahonen
              Kalle Viironen Kalle Viironen
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes