Qt 中无法使用搜狗输入法解决方法

解决Qt中无法使用搜狗输入法的方法

在 Ubuntu 系统中使用 Qt 发现有的系统无法使用搜狗等中文输入法,该方法用于解决搜狗输入法不能在 Qt 等软件中使用的问题。
(题外话:Ubuntu 19 的 VS Code 软件不能使用搜狗输入法是 Ubuntu 软件商店安装包的问题,只能从 VS Code 官网重新下载安装解决。)

步骤

1. 编译 fcitx-qt5 源码

1.1 编译 fcitx-qt 需要 cmake,安装 cmake 命令,如果已经安装,请略过;

1
sudo apt-get install cmake

1.2 安装 fcitx-libs-dev;

1
sudo apt-get install fcitx-libs-dev

1.3 设置qmake的环境变量,这一步很重要且环境变量的值因人而异

1.3.1. 首先确定你的Qt的安装目录,我这里是~/software/Qt5.6.0/,你的或者可能在/home/<用户名>/Qt5.6.0/
1.3.2.
export PATH="/5.6/gcc_64/bin":$PATH

1.4 下载fcitx-libs 源码

1.4.1
原文的 git clone git@github.com:fcitx/fcitx-qt5.git 不可行,需要修改为https://github.com/fcitx/fcitx-qt5
1.4.2.
git clone https://github.com/fcitx/fcitx-qt5

1.5 编译 fcitx-qt5

1
2
3
4
cd fcitx-qt5
cmake .
make
sudo make install

2. 拷贝 so 文件

2.1找到文件

编译完成后,需要把编译得到的 libfcitxplatforminputcontextplugin.so 拷贝到 Qt5.5 安装目录的 Tools/QtCreator/bin/plugins/platforminputcontexts 或 Qt5.6 安装目录的 Tools/QtCreator/lib/Qt/plugins/platforminputcontexts,注意:两个目录根据你的Qt版本而定,Qt安装目录因人而异。

2.2复制:

Qt 5.5:cp platforminputcontext/libfcitxplatforminputcontextplugin.so /Tools/QtCreator/bin/plugins/platforminputcontexts
Qt 5.6:cp platforminputcontext/libfcitxplatforminputcontextplugin.so /Tools/QtCreator/lib/Qt/plugins/platforminputcontexts
我这里是:cp platforminputcontext/libfcitxplatforminputcontextplugin.so ~/software/Qt5.6.0/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts

3. 添加额外的环境变量

1
2
echo 'export XMODIFIERS=@im=fcitx' >> .bashrc 
echo 'export QT_IM_MODULE=fcitx' >> .bashrc

大功告成!

遇到的问题

说明:本人系统为 Ubuntu 16.04 LTS 英文版 ,遇到的问题基本和原文一样

1. 安装CMake失败

问题描述:sudo apt-get install cmake 执行到 92 % 时提示下载失败,原因是找不到 IP 地址。
问题解决:觉得应该是安装包源的问题,于是修改了系统默认的源。

1
2
3
System Settings -> Software & Updates -> Ubuntu Software -> Download from 从原来的 China 改为 Main server,最后再
sudo apt-get update
sudo apt-get install cmake

2. CMake 错误

问题描述:

1
2
3
4
5
6
7
8
9
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!

解决方法:
2.1. 到这个页面 https://launchpad.net/ubuntu/+source/extra-cmake-modules/1.4.0-0ubuntu1 下载 extra-cmake-modules_1.4.0.orig.tar.xz
2.2. 解压后编译安装

1
2
3
4
cd extra-cmake-modules-1.4.0
cmake .
make
sudo make install

3. 安装 extra-cmake-modules-1.4.0 失败

问题描述:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$:~/Downloads/extra-cmake-modules-1.4.0$ cmake .
CMake Warning at tests/CMakeLists.txt:28 (find_package):
Could not find a package configuration file provided by "Qt5LinguistTools"
with any of the following names:
Qt5LinguistToolsConfig.cmake
qt5linguisttools-config.cmake
Add the installation prefix of "Qt5LinguistTools" to CMAKE_PREFIX_PATH or
set "Qt5LinguistTools_DIR" to a directory containing one of the above
files. If "Qt5LinguistTools" provides a separate development package or
SDK, be sure it has been installed.
-- Looking for Sphinx Documentation Builder...
-- Sphinx Documentation Builder not found - documentation will not be built (see http://sphinx-doc.org/)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cposture/Downloads/extra-cmake-modules-1.4.0

解决方法:
设置 CMAKE_PREFIX_PATH 环境变量 为 qtbase 目录(<Qt安装目录>/5.6/Src/qtbase/),我这里为:
export CMAKE_PREFIX_PATH=”~/software/Qt5.6.0/5.6/Src/qtbase/“
如果还是不行,则修改为

1
export CMAKE_PREFIX_PATH="/home/cposture/software/Qt5.6.0/5.6/gcc_64/lib/cmake/"

4. 缺少 xkbcommon 包

问题描述:

1
2
3
4
 -- 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")

解决方法:
2.1. 到 http://xkbcommon.org/ 下载最新版的 xkbcommon
2.2. 解压后,

1
2
3
4
sudo apt-get install bison
./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --disable-x11
make
sudo make install
Comments

:D 一言句子获取中...

Loading...Wait a Minute!