Qt 编译fcitx-qt5 插件支持中文输入法

前言

在Linux系统上会遇到Qt开发的程序无法输入中文的情况,原因就是因为输入法框架是采用的fcitx,而不是ibus,Qt默认只支持ibus输入法框架。在Qt/5.15.2/gcc_64/plugins/platforminputcontexts/路径下可以看到,只有libibusplatforminputcontextplugin.so,没有libfcitxplatforminputcontextplugin.so。而本文的目的就是编译出libfcitxplatforminputcontextplugin.so动态库,使其支持fcitx输入法框架,从而支持输入中文。

下载源代码

bash 复制代码
git clone https://github.com/fcitx/fcitx-qt5

注意,是fcitx-qt5、fcitx-qt5、fcitx-qt5,fcitx 组织下还有一个容易混淆的仓库,请仔细区分。

构建编译fcitx-qt5

首先需要安装必备的依赖环境:

复制代码
sudo apt install extra-cmake-modules

在这之前,最好设置Qt的环境变量:

ruby 复制代码
export PATH=$PATH:/home/leo/Qt/5.15.2/bin/

不设置的话也行,可以 cmake 手动指定Qt目录。

如果你是 Qt 6,那么还需要修改一下fcitx-qt5的CMakeLists.txt文件:

vbnet 复制代码
option(ENABLE_QT4 "Enable Qt 4" On)
option(ENABLE_QT5 "Enable Qt 5" Off)
option(ENABLE_QT6 "Enable Qt 6" On)
option(BUILD_ONLY_PLUGIN "Build only plugin" Off)
option(BUILD_STATIC_PLUGIN "Build plugin as static" Off)
option(WITH_FCITX_PLUGIN_NAME "Enable plugin name with fcitx" On)

ENABLE_QT5改为off,ENABLE_QT6改为on

然后创建一个build目录:

bash 复制代码
mkdir build
cd build

执行cmake命令

ini 复制代码
cmake .. -DENABLE_LIBRARY=false

执行make

go 复制代码
make

在build目录下的qt5/platforminputcontext就有需要的libfcitx5platforminputcontextplugin.so插件动态库了。

安装(可选)

make install 命令会将插件装到指定qt环境下的plugins目录下

go 复制代码
make install

也可自行将动态库拷贝到对应路径下或者自己的Qt程序打包路径下。

错误解决

找不到 FcitxConfig.cmake

swift 复制代码
CMake Error at CMakeLists.txt:36 (find_package):
By not providing "FindFcitx.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Fcitx", but
CMake did not find one.

Could not find a package configuration file provided by "Fcitx" (requested
version 4.2.8) with any of the following names:

  FcitxConfig.cmake
  fcitx-config.cmake

Add the installation prefix of "Fcitx" to CMAKE_PREFIX_PATH or set
"Fcitx_DIR" to a directory containing one of the above files. If "Fcitx"
provides a separate development package or SDK, be sure it has been installed.

 -- Configuring incomplete, errors occurred!
See also "/media/veracrypt/mythware/gerrit/QT/ClassroomManagement/ClassroomManagement/Submodules/fcitx/fcitx-qt5/build/CMakeFiles/CMakeOutput.log".

解决方案

命令行增加 "-DENABLE_LIBRARY=false" 参数

ini 复制代码
cmake .. -DENABLE_LIBRARY=false

找不到 ECMConfig.cmake

sql 复制代码
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!
See also "/home/shana/fcitx-qt5/build/CMakeFiles/CMakeOutput.log".

解决方案:

安装extra-cmake-modules包:

复制代码
sudo apt install extra-cmake-modules

找不到 Qt5Config.cmake

解决方案:

命令行增加-DQt5_DIR=[Qt目录]/lib/cmake/Qt5参数

ini 复制代码
cmake .. -DENABLE_LIBRARY=false -DQt5_DIR=[Qt目录]/lib/cmake/Qt5
相关推荐
尽兴-24 分钟前
如何将多个.sql文件合并成一个:Windows和Linux/Mac详细指南
linux·数据库·windows·sql·macos
kfepiza24 分钟前
Netplan 中 bridges、bonds、ethernets、vlans 之间的关系 笔记250711
linux·tcp/ip·shell
小小不董41 分钟前
深入理解oracle ADG和RAC
linux·服务器·数据库·oracle·dba
杰夫贾维斯2 小时前
CentOS Linux 8 的系统部署 Qwen2.5-7B -Instruct-AWQ
linux·运维·人工智能·机器学习·centos
kfepiza2 小时前
Netplan 配置网桥(Bridge)的模板笔记250711
linux·tcp/ip·ubuntu
kfepiza3 小时前
用Netplan配置网桥bridge笔记250711
linux·ubuntu·debian
CodeWithMe3 小时前
【Note】Linux Kernel 实时技术深入:详解 PREEMPT_RT 与 Xenomai
linux·运维·服务器
AI迅剑3 小时前
模块三:现代C++工程实践(4篇)第三篇《C++与系统编程:Linux内核模块开发入门》
linux·运维·服务器
专一的咸鱼哥3 小时前
Linux驱动开发(platform 设备驱动)
linux·运维·驱动开发
不脱发的程序猿4 小时前
SoC程序如何使用单例模式运行
linux·嵌入式