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

2023-12-11 14:01

本文主要是介绍Qt 编译fcitx-qt5 插件支持中文输入法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前言

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

下载源代码

git clone https://github.com/fcitx/fcitx-qt5

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

构建编译fcitx-qt5

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

sudo apt install extra-cmake-modules

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

export PATH=$PATH:/home/leo/Qt/5.15.2/bin/

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

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

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目录:

mkdir build
cd build

执行cmake命令

cmake .. -DENABLE_LIBRARY=false

执行make

make

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

安装(可选)

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

$ make install
[  4%] Automatic MOC for target fcitxplatforminputcontextplugin
[  4%] Built target fcitxplatforminputcontextplugin_autogen
[100%] Built target fcitxplatforminputcontextplugin
Install the project...
-- Install configuration: ""
-- Installing: /home/leo/Qt/5.15.2/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so
-- Set runtime path of "/home/leo/Qt/5.15.2/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so" to ""

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

错误解决

找不到 FcitxConfig.cmake

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.cmakefcitx-config.cmakeAdd 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” 参数

cmake .. -DENABLE_LIBRARY=false

找不到 ECMConfig.cmake

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.cmakeecm-config.cmakeAdd 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参数

cmake .. -DENABLE_LIBRARY=false -DQt5_DIR=[Qt目录]/lib/cmake/Qt5

这篇关于Qt 编译fcitx-qt5 插件支持中文输入法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/480948

相关文章

华为鸿蒙HarmonyOS 5.1官宣7月开启升级! 首批支持名单公布

《华为鸿蒙HarmonyOS5.1官宣7月开启升级!首批支持名单公布》在刚刚结束的华为Pura80系列及全场景新品发布会上,除了众多新品的发布,还有一个消息也点燃了所有鸿蒙用户的期待,那就是Ha... 在今日的华为 Pura 80 系列及全场景新品发布会上,华为宣布鸿蒙 HarmonyOS 5.1 将于 7

CnPlugin是PL/SQL Developer工具插件使用教程

《CnPlugin是PL/SQLDeveloper工具插件使用教程》:本文主要介绍CnPlugin是PL/SQLDeveloper工具插件使用教程,具有很好的参考价值,希望对大家有所帮助,如有错... 目录PL/SQL Developer工具插件使用安装拷贝文件配置总结PL/SQL Developer工具插

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

maven中的maven-antrun-plugin插件示例详解

《maven中的maven-antrun-plugin插件示例详解》maven-antrun-plugin是Maven生态中一个强大的工具,尤其适合需要复用Ant脚本或实现复杂构建逻辑的场景... 目录1. 核心功能2. 典型使用场景3. 配置示例4. 关键配置项5. 优缺点分析6. 最佳实践7. 常见问题

Qt之QMessageBox的具体使用

《Qt之QMessageBox的具体使用》本文介绍Qt中QMessageBox类的使用,用于弹出提示、警告、错误等模态对话框,具有一定的参考价值,感兴趣的可以了解一下... 目录1.引言2.简单介绍3.常见函数4.按钮类型(QMessage::StandardButton)5.分步骤实现弹窗6.总结1.引言

Qt中Qfile类的使用

《Qt中Qfile类的使用》很多应用程序都具备操作文件的能力,包括对文件进行写入和读取,创建和删除文件,本文主要介绍了Qt中Qfile类的使用,具有一定的参考价值,感兴趣的可以了解一下... 目录1.引言2.QFile文件操作3.演示示例3.1实验一3.2实验二【演示 QFile 读写二进制文件的过程】4.

MyBatis分页插件PageHelper深度解析与实践指南

《MyBatis分页插件PageHelper深度解析与实践指南》在数据库操作中,分页查询是最常见的需求之一,传统的分页方式通常有两种内存分页和SQL分页,MyBatis作为优秀的ORM框架,本身并未提... 目录1. 为什么需要分页插件?2. PageHelper简介3. PageHelper集成与配置3.

Maven 插件配置分层架构深度解析

《Maven插件配置分层架构深度解析》:本文主要介绍Maven插件配置分层架构深度解析,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Maven 插件配置分层架构深度解析引言:当构建逻辑遇上复杂配置第一章 Maven插件配置的三重境界1.1 插件配置的拓扑

Idea插件MybatisX失效的问题解决

《Idea插件MybatisX失效的问题解决》:本文主要介绍Idea插件MybatisX失效的问题解决,详细的介绍了4种问题的解决方法,具有一定的参考价值,感兴趣的可以了解一下... 目录一、重启idea或者卸载重装MyBATis插件(无需多言)二、检查.XML文件与.Java(该文件后缀Idea可能会隐藏