最近在ubantu上使用Qt开发进行开发,遇到不能使用输入法输入中文的问题,有点头疼,于是百度谷歌双管齐下,查阅各方资料,综合各种解决方案,kill 了这个问题,在此做下笔记,也希望能够帮助到同样遇到此问题的人。
- 系统版本: ubantu 16.04 LTS
- 输入法: 搜狗输入法
- 本人Qt版本: Qt5.6
- 解决方法,编译 fcitx-qt5 源码
解决步骤
前期准备工作
安装cmake
1
| sudo apt-get install cmake
|
安装fcitx-libs-dev
1
| sudo apt-get install fcitx-libs-dev
|
设置环境变量(根据个人Qt的安装位置做修改)
1
| export PATH="/home/ProgramFiles/Qt5.6.1/5.6/gcc_64/bin":$PATH
|
下载fcitx-qt5源码(如果显示没有权限获取,及表明没有秘钥,则可以打开这个网址直接到github上去下载压缩包,再解压即可)
1
| git clone https://github.com/fcitx/fcitx-qt5
|
执行编译操作
编译fcitx-qt:
1 2 3 4
| cd fcitx-qt5 cmake . make sudo make install
|
拷贝编译得到的so文件
编译成功之后,将编译得到的“libfcitxplatforminputcontextplugin.so”文件拷贝到Qt的安装目录“Tools/QtCreator/bin/plugins/platforminputcontexts” 或“Tools/QtCreator/lib/Qt/plugins/platforminputcontext”之中,两个目录由安装情况而定,有的会是第一个路径,有的则是第二个路径,然后再继续将这个文件放在“Qt5.6.1/5.6/gcc_64/plugins/platforminputcontexts”之下,最后重启Qt或则重启电脑则可以了。
在此过程中可能遇到的问题
缺少ECMConfig.cmake 和ecm-config.cmake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| CMake Error at CMakeLists.txt:8 (find_package):
Could not find a package configuration file provided by "ECM" (requested
version 1.4.0) with any of the following names:
ECMConfig.cmake
ecm-config.cmake
Add the installation prefix of "ECM" to CMAKE_PREFIX_PATH or set "ECM_DIR"
to a directory containing one of the above files. If "ECM" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
|
下载 extra-cmake-modules_1.4.0.orig.tar.xz
链接: https://launchpad.net/ubuntu/+source/extra-cmake-modules/1.4.0-0ubuntu1
解压后进行如下操作:
1 2 3
| cd extra-cmake-modules-1.4.0 cmake . sudo make install
|
缺少Qt5Config.cmake 和qt5-config.cmake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| CMake Error at CMakeLists.txt:29 (find_package):
Could not find a package configuration file provided by "Qt5" (requested
version 5.1.0) with any of the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
|
设置 CMAKE_PREFIX_PATH 环境变量
1
| export CMAKE_PREFIX_PATH="/home/cc/ProgramFiles/Qt5.6.1/5.6/gcc_64/lib/cmake/"
|
缺少xkbcommon
1 2 3 4 5 6 7
| - Found PkgConfig: /usr/bin/pkg-config (found version "0.26")
-- Could NOT find XKBCommon_XKBCommon (missing: XKBCommon_XKBCommon_LIBRARY XKBCommon_XKBCommon_INCLUDE_DIR)
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find XKBCommon (missing: XKBCommon_LIBRARIES XKBCommon) (Required is at least version "0.5.0")
|
进行安装即可.
1 2 3 4 5 6 7 8 9 10 11
| sudo apt-get install libxkcommon-dev ``` 编译: ```bash sudo apt-get install bison
./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --disable-x11
make
sudo make install
|
参考资料
http://my.oschina.net/lieefu/blog/505363
http://www.gszadc.com/448428224.html
http://www.07net01.com/2016/06/1558676.html