LoginSignup
4
4

More than 5 years have passed since last update.

自作QtアプリやQtCreatorで日本語入力ができない問題の解決法

Last updated at Posted at 2019-03-23

問題

Qtの公式サイトから落としてきたインストーラーでインストールしたQtCreatorやQtにリンクしてある自作アプリケーションで日本語入力ができない。

環境

  • Linux Mint 19.1
  • Qt 5.12.0(インストールした方)
  • QtCreator 4.8.1(Based on Qt 5.12.0)
  • Qt 5.9.5(Linux Mintにある方)
  • インプットメソッド:fcitx

原因の調査

調べてみたら

  • ~/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts
  • ~/Qt/5.12.0/gcc_64/plugins/platforminputcontexts

libfcitxplatforminputcontextplugin.soがないためらしい。

QT_IM_MODULE環境変数がfcitxになっていないからと言うWebページもあったが、私の環境では

$ env | grep QT
QT4_IM_MODULE=fcitx
QT_QPA_PLATFORMTHEME=qt5ct
QT_ACCESSIBILITY=1
QT_IM_MODULE=fcitx

とちゃんとfcitxになっていた。

fcitx-qt5をコンパイル

参考:Ubuntu 16.04LTSでのQtCreator日本語入力

$ git clone https://github.com/fcitx/fcitx-qt5.git
$ cd fcitx-qt5/
$ sudo apt install cmake ecm extra-cmake-modules fcitx-libs-dev
$ cmake . -DCMAKE_PREFIX_PATH=/home/subbbbbb/Qt/5.12.0/gcc_64

怒られた。

CMake Error at /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake:9 (message):
  Failed to find "GL/gl.h" in "/usr/include/libdrm".
Call Stack (most recent call first):
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:174 (include)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake:89 (find_package)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package)
  CMakeLists.txt:31 (find_package)

それっぽいのを適当に入れる。

$ sudo apt install mesa-common-dev

すると/usr/include/GLフォルダができて、その中にgl.hがあったため~/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmakeの4行目を

set(_GL_INCDIRS "/usr/include/libdrm")

から

set(_GL_INCDIRS "/usr/include")

に書き換えて保存する。
再実行するとまた怒られた

$ cmake . -DCMAKE_PREFIX_PATH=/home/subbbbbb/Qt/5.12.0/gcc_64
CMake Error at /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:15 (message):
  The imported target "Qt5::Gui" references the file

     "/usr/lib/x86_64-linux-gnu/libEGL.so"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake:50 (_qt5_Gui_check_file_exists)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake:72 (_qt5gui_find_extra_libs)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:174 (include)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake:89 (find_package)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package)
  CMakeLists.txt:31 (find_package)


-- Configuring incomplete, errors occurred!

/usr/lib/x86_64-linux-gnu/libEGL.soがないらしい。

$ ls -l /usr/lib/x86_64-linux-gnu/libEGL*
libEGL.so -> libEGL.so.1.0.0
libEGL.so.1 -> libEGL.so.1.1.0*
libEGL.so.1.1.0*
libEGL_mesa.so.0 -> libEGL_mesa.so.0.0.0
libEGL_mesa.so.0.0.0
libEGL_nvidia.so.0 -> libEGL_nvidia.so.410.78*
libEGL_nvidia.so.410.78*

存在しないファイルlibEGL.so.1.0.0へのシンボリックリンクになっていたため、リンクを貼り直す。

$ sudo ln -si libEGL.so.1.1.0 libEGL.so

再度実行したらまた同じようなことを言われた。

$ cmake . -DCMAKE_PREFIX_PATH=/home/subbbbbb/Qt/5.12.0/gcc_64
CMake Error at /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:15 (message):
  The imported target "Qt5::Gui" references the file

     "/usr/lib/x86_64-linux-gnu/libGL.so"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake:50 (_qt5_Gui_check_file_exists)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake:74 (_qt5gui_find_extra_libs)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:174 (include)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake:89 (find_package)
  /home/subbbbbb/Qt/5.12.0/gcc_64/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package)
  CMakeLists.txt:31 (find_package)


-- Configuring incomplete, errors occurred!

これもリンク切れとなっていたため、同様に貼り直す。

sudo ln -si libGL.so.1.7.0 libGL.so

4度目の正直

$ cmake . -DCMAKE_PREFIX_PATH=/home/subbbbbb/Qt/5.12.0/gcc_64
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Could NOT find XKBCommon_XKBCommon (missing: XKBCommon_XKBCommon_LIBRARY XKBCommon_XKBCommon_INCLUDE_DIR) (found version "")
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find XKBCommon (missing: XKBCommon_LIBRARIES XKBCommon) (Required
  is at least version "0.5.0")
Call Stack (most recent call first):
  /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindXKBCommon.cmake:30 (find_package_handle_standard_args)
  CMakeLists.txt:33 (find_package)


-- Configuring incomplete, errors occurred!

xkbcommonがないと言われる。入れる。

$ sudo apt install libxkbcommon-dev

5度目の正直

cmake . -DCMAKE_PREFIX_PATH=/home/subbbbbb/Qt/5.12.0/gcc_64
-- Found XKBCommon_XKBCommon: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (found version "0.8.0") 
-- Found XKBCommon: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (found suitable version "0.8.0", minimum required is "0.5.0") found components:  XKBCommon 
-- Checking for module 'fcitx'
--   Found fcitx, version 4.2.9.6
-- Checking for module 'fcitx-config'
--   Found fcitx-config, version 4.2.9.6
-- Checking for module 'fcitx-utils'
--   Found fcitx-utils, version 4.2.9.6
-- fcitx4-config found /usr/bin/fcitx4-config
-- Found Fcitx: 4.2.9.6 (Required is at least version "4.2.8") 
-- Looking for dgettext
-- Looking for dgettext - found
-- Found LIBINTL: /usr/include  
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- The following OPTIONAL packages have been found:

 * PkgConfig

-- The following REQUIRED packages have been found:

 * ECM (required version >= 1.4.0)
 * Qt5DBus
 * Qt5Widgets
 * Qt5Concurrent
 * Qt5 (required version >= 5.1.0)
 * Qt5Gui (required version >= 5.1.0)
 * XKBCommon (required version >= 0.5.0), Keyboard handling library using XKB data, <http://xkbcommon.org>
 * Fcitx (required version >= 4.2.8)
 * LibIntl
 * Qt5Core

-- Configuring done
-- Generating done
-- Build files have been written to: /home/subbbbbb/Documents/MyFolder/2019/qt_fcitx/fcitx-qt5

やっと通った。あとはコンパイルするだけ。

$ make -j 6

できたプラグインをコピーする。

$ cd platforminputcontext/
$ cp libfcitxplatforminputcontextplugin.so ~/Qt/5.12.0/gcc_64/plugins/platforminputcontexts/
$ cp libfcitxplatforminputcontextplugin.so ~/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/

1つ目のコピーの後、自作アプリケーションを再起動で日本語入力ができるようになった。
2つ目のコピーの後、QtCreatorを再起動で日本語入力ができるようになった。

別の解決法

OSにデフォルトで入っているQtとインストールしたQtのバージョンが違うとセグフォを起こすと言う情報があったのと、昔やっても日本語入力が出来るようにならなかったような記憶があったため後回しにしたが、
/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontextsにあるlibfcitxplatforminputcontextplugin.soをコピーしても同じように日本語入力ができるようになった。今までの苦労は一体…

まとめ

/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontextsにあるlibfcitxplatforminputcontextplugin.so
~/Qt/5.12.0/gcc_64/plugins/platforminputcontexts/
~/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/
コピーしてみて日本語入力が出来るようにならなかったら、仕方がないのでfcitx-qt5をコンパイルしましょう。

参考

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4