用 Qt 官方的 Online Installer 安装的,没有做特别的设置。
我搜索了网上的方法,试验后仍没有解决。下面是试验的步骤:
# 1. 准备 Fcitx5 Qt6 插件的源码及编译目录
Git clone https://Github.com/fcitx/fcitx5-qt.Git ~/fcitx5-qt
cd ~/fcitx5-qt
Git checkout 5.1.3
mkdir build
# 2. 准备 编译环境
export LD_LIBRARY_PATH=/opt/Qt/Tools/QtCreator/lib/Qt/lib
export PATH=/opt/Qt/Tools/QtCreator/lib/Qt/bin:/opt/Qt/6.6.1/gcc_64/bin:/opt/Qt/Tools/CMake/bin:$PATH
# 3. 编译插件
cmake -DENABLE_QT5=Off -DENABLE_QT4=Off -DENABLE_QT6=On -DBUILD_ONLY_PLUGIN=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-B build/
cd build
make
# 4. 复制 插件库 到 QtCreator
sudo cp qt6/platforminputcontext/libfcitx5platforminputcontextplugin.so \
/opt/Qt/6.6.1/gcc_64/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so
sudo cp qt6/platforminputcontext/libfcitx5platforminputcontextplugin.so \
/opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so
按照上面的方法试验后仍然不能输入中文,若打开 QtCreator->Terminal ,执行 fcitx5-qt6-immodule-probing
,你会看到:
qt.qpa.theme.dbus: Session DBus not running.
qt.qpa.theme.dbus: Application will not react to setting changes.
Check your DBus installation.
QT_QPA_PLATFORM=xcb
QT_IM_MODULE=fcitx
IM_MODULE_CLASSNAME=fcitx::QFcitxPlatformInputContex
请问哪位有没有遇到同样的问题,能共享一下解决方案否?
Konsole 输出:
env | grep DBUS
KONSOLE_DBUS_SERVICE=:1.158
KONSOLE_DBUS_SESSION=/Sessions/4
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
KONSOLE_DBUS_WINDOW=/Windows/1
Qt Creator → Terminal 输出:
env | grep DBUS
DBUS_SESSION_BUS_ADDRESS=/run/user/1000/bus
若用命令 QT_DEBUG_PLUGINS=1 /opt/Qt/Tools/QtCreator/bin/qtcreator.sh -dograb
运行 QtCreator
,会发现类似下面的信息:
qt.core.plugin.factoryloader: Got keys from plugin meta data QList("ibus")
qt.core.plugin.factoryloader: looking at "/opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so"
qt.core.plugin.loader: Found metadata in lib /opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so, metadata=
{
"IID": "org.qt-project.Qt.QPlatformInputContextFactoryInterface.5.1",
"MetaData": {
"Keys": [
"fcitx",
"fcitx5"
]
},
"archlevel": 1,
"className": "QFcitx5PlatformInputContextPlugin",
"debug": false,
"version": 394752
}
qt.core.plugin.factoryloader: Got keys from plugin meta data QList("fcitx", "fcitx5")
qt.core.plugin.factoryloader: checking directory path "/opt/Qt/Tools/QtCreator/bin/platforminputcontexts" ...
qt.core.library: "/opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so" cannot load: Cannot load library /opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so: (/opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so: undefined symbol: _ZN13QRasterWindow11resizeEventEP12QResizeEvent, version Qt_6)
qt.core.plugin.loader: QLibraryPrivate::loadPlugin failed on "/opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so" : "Cannot load library /opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so: (/opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so: undefined symbol: _ZN13QRasterWindow11resizeEventEP12QResizeEvent, version Qt_6)"
我在上面贴出的信息中有下面这个重点:
Sauntor:
qt.core.library: "/opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so" cannot load: Cannot load library /opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so: (/opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so: undefined symbol: _ZN13QRasterWindow11resizeEventEP12QResizeEvent, version Qt_6)
所以,我冒出一个大胆的猜测:Qt Online Installer 安装的 QtCreator 所使用的 Qt 运行时(/opt/Qt/Tools/QtCreator/lib/Qt)是商用版(与开源版有区别)的。
然后我便尝试用开源版替代:
mv /opt/Qt/Tools/QtCreator/lib/Qt /opt/Qt/Tools/QtCreator/lib/Qt.online
ln -s /opt/Qt/6.6.1/gcc_64 /opt/Qt/Tools/QtCreator/lib/Qt
哈哈,竟然可以正常输入中文了!
但是这个方案有个问题:在进行 Qt/QtCreator 版本更新时可能会需要重新操作一遍(因为更新后/opt/Qt/6.6.1/gcc_64 会被删掉,然后创建类似/opt/Qt/6.6.2 的目录),而且官方 QtCreator 的商业版 Qt 运行时可能会错误覆盖/opt/Qt/6.6.1/gcc_64,所以要在运行/opt/Qt/MaintenanceTool 真正更新 Qt 版本之前,把软连接恢复:
rm /opt/Qt/Tools/QtCreator/lib/Qt
mv /opt/Qt/Tools/QtCreator/lib/Qt.online /opt/Qt/Tools/QtCreator/lib/Qt
期待更好的解决办法,欢迎大家继续留言讨论
尝试过用系统库替代:
rm /opt/Qt/Tools/QtCreator/lib/Qt
mkdir /opt/Qt/Tools/QtCreator/lib/Qt
ln -s /usr/bin /opt/Qt/Tools/QtCreator/lib/Qt/bin
ln -s /usr/lib64 /opt/Qt/Tools/QtCreator/lib/Qt/lib
ln -s /usr/lib64/qt6/plugins /opt/Qt/Tools/QtCreator/lib/Qt/plugins
ln -s /usr/lib64/qt6/qml /opt/Qt/Tools/QtCreator/lib/Qt/qml
但是会输出这样的信息:
/opt/Qt/Tools/QtCreator/bin/qtcreator: /opt/Qt/Tools/QtCreator/bin/../lib/Qt/lib/libQt6Core.so.6: version `Qt_6_PRIVATE_API' not found (required by /opt/Qt/Tools/QtCreator/bin/../lib/qtcreator/libExtensionSystem.so.12)
/opt/Qt/Tools/QtCreator/bin/qtcreator: /opt/Qt/Tools/QtCreator/bin/../lib/Qt/lib/libQt6Core.so.6: version `Qt_6_PRIVATE_API' not found (required by /opt/Qt/Tools/QtCreator/bin/../lib/qtcreator/libUtils.so.12)
/opt/Qt/Tools/QtCreator/bin/qtcreator: /opt/Qt/Tools/QtCreator/bin/../lib/Qt/lib/libQt6Core.so.6: version `Qt_6_PRIVATE_API' not found (required by /opt/Qt/Tools/QtCreator/bin/../lib/qtcreator/libAggregation.so.12)
上面信息的貌似证明我的猜测没错:Qt Online Installer 安装的所有二进制文件都是商用版的,与开源社区提供的在 ABI 上不兼容
把修复方案整理成了脚本,内容如下:
#!/bin/bash
# Qt 6 Creator Fcitx5 Issue Fixer
# Filename: qt6creator-fcitx5-fixer
app=$0
function fixer_help
{
cat <<EOF
$app --fix|--clean QT_INSTALL_DIR QT_VERSION
--fix 执行修复动作
--clean 恢复修复动作所做的变动
QT_INSTALL_DIR Qt 安装目录
QT_VERSION 修复时所使用的 Qt 版本号
示例:
qt6creator-fcitx5-fixer --fix /opt/Qt 6.6.1
qt6creator-fcitx5-fixer --clean /opt/Qt 6.6.1
关于 Qt 版本号:
打开 QtCreator->帮助->About Qt Creator(关于),找到 "Based on Qt 6.x.y"这样的字眼
那么 6.x.y 就是所要使用的版本号
但是!!你必须安装相应的 Qt 工具链!! 可以运行 QT_INSTALL_DIR/MaintenanceTool 来验证/补充安装
慎重!!你也可以尝试用其他你已安装的 6.x 版的 Qt 替代
EOF
}
if [ "$#" -ne 3 ]; then
fixer_help
exit 1
fi
qt_cmd=$1
shift
qt_dir=$(readlink -f $1)
qt_ver=$2
qt_lib=$qt_dir/Tools/QtCreator/lib/Qt
case "$qt_cmd" in
--fix)
# 1. 准备 Fcitx5 Qt6 插件的源码及编译目录
f5_src=$(mktemp -d)
f5_bin=$(mktemp -d)
Git clone https://Github.com/fcitx/fcitx5-qt.git $f5_src
cd $f5_src
git checkout $(git describe --abbrev=0 --tags --match "[0-9]*" $(git rev-list --tags --max-count=1))
mkdir -p $f5_bin
# 2. 准备 编译环境
export LD_LIBRARY_PATH=$qt_dir/$qt_ver/lib
export PATH=$qt_dir/$qt_ver/gcc_64/bin:$qt_dir/Tools/CMake/bin:$PATH
# 3. 编译插件
cmake \
-DENABLE_QT5=OFF \
-DENABLE_QT4=OFF \
-DENABLE_QT6=ON \
-DBUILD_ONLY_PLUGIN=ON \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
-S $f5_src \
-B $f5_bin
cd $f5_bin
make
# 4. 复制 插件库 到 QtCreator
cp -fv qt6/platforminputcontext/libfcitx5platforminputcontextplugin.so \
$qt_dir/$qt_ver/gcc_64/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so
# 5. 清理临时文件
rm -rf $f5_bin
rm -rf $f5_src
# 6. 替换官方库
if [ -L $qt_lib ]; then
rm -fv $qt_lib
else
mv -fv $qt_lib $qt_lib.online
fi
ln -vsT $qt_dir/$qt_ver $qt_lib
echo "Fixed! Happy to play with Qt Creator!"
;;
--clean)
rm -fv $qt_dir/$qt_ver/gcc_64/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so
if [ -L $qt_lib ]; then
rm -fv $qt_lib
[ -d $qt_lib.online ] && mv -fvT $qt_lib.online $qt_lib
fi
echo "Cleaned up!"
;;
*)
fixer_help
;;
esac
下载连接:
qt6creator-fcitx5-fixer.tar.gz (1.4 KB)
2赞
benren
(benren)
2023年12月27日 06:42
10
你的解决方案不好。主要是这条 cmake 命令行错了。应该再加一个参数:
cmake -DCMAKE_PREFIX_PATH= /opt/Qt/Tools/QtCreator/lib/cmake/ ...
这样编译出来的 fcitx5 qt 模块才是安装器安装出来的 qt6. 不然像你现在这样子编译出来的就和系统的 qt6 相关。Qt6 的各个版本之间没有承诺二进制兼容。