解决Ubuntu下的qtcreator不能输入中文的问题

QT中文输入的解决方法

最近一段时间在学习QT,可一直没法在QT中输入中文,中间也在网上尝试很多方法,可都是无法解决,一直在妥协和不服中徘徊,有段时间使用ibus的输入法勉强输入中文,可是每次使用中都无法在qtcreator中切换中英文,总需要到终端中切换好输入法后,使用输入法,极其不方便,对于我这种有强迫症的人来说,一直想解决这个问题,于是不服输的我今天又开始尝试解决这个问题,皇天不负有心人,今天总算解决了 。

补充说明:本人使用的系统是Ubuntu16.04,QT 是qt5.4.1,其他版本可做参考,希望这个方法能够帮助大家,尤其是像我一样有强迫症的朋友们。

分析

qt程序输入中文需要qt插件,而自带的是没有fcitx输入法插件,意味着你想使用fcitx的输入法,是无法在qt中使用的,所以需要补充插件,网上给出的方法是从把/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/目录下的libfcitxplatforminputcontextplugin.so拷贝到QT按照的对应目录下,不出意外的话,还是无法解决问题,原因是Qt5.4 及以后的版本对之前 Qt5 版本不再二进制兼容,libfcitxplatforminputcontextplugin.so 需要编译最新的 fcitx-qt5。可以下载编译好的 libfcitxplatforminputcontextplugin.so

具体步骤

1.编译编译 fcitx-qt 需要 cmake,安装cmake,已安装,可忽略。

sudo apt install cmake

2.安装 fcitx-libs-dev

sudo apt install fcitx-libs-dev

3.设置 qmake 的环境变量,即将qmake的路径设置到PATH环境变量中。
4.在git下载fcitx-qt5的源码(没有安装git,按照提示进行安装)

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

5.进入fcitx-qt5目录进行编译

cd fcitx-qt5
cmake .
make
sudo  make  install

6.将编译得到 libfcitxplatforminputcontextplugin.so 拷贝到 Qt安装目录的 Qt5.4.1/Tools/QtCreator/bin/plugins/platforminputcontexts和Qt5.4.1/5.4/gcc_64/plugins/platforminputcontexts

7.重启系统,QT便可正常输入中文。

不出意外就出意外了,正常来说,大家在第6步编译时,会出现大量问题,博主踩过的坑,也让大家体验一下,哈哈哈~

下面解决这些问题

1.在cmake .时,会出现类似以下的问题
CMake Error at CMakeLists.txt:9 (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/dell/fcitx-qt5/CMakeFiles/CMakeOutput.log”.

解决Ubuntu下的qtcreator不能输入中文的问题_第1张图片
解决方法:下载extra-cmake-modules_1.4.0.orig.tar.xz
下载网址:https://launchpad.net/ubuntu/+source/extra-cmake-modules/1.4.0-0ubuntu1

tar -xJf extra-cmake-modules_1.4.0.orig.tar.xz    # 解压
cd extra-cmake-modules-1.4.0
cmake .
make
sudo make install

2.在进入fcitx-qt5目录,进行cmake .,出现新问题~
– Found PkgConfig: /usr/bin/pkg-config (found version “0.29.1”)
– Could NOT find XKBCommon_XKBCommon (missing: XKBCommon_XKBCommon_LIBRARY XKBCommon_XKBCommon_INCLUDE_DIR)
CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find XKBCommon (missing: XKBCommon_LIBRARIES XKBCommon) (Required
is at least version “0.5.0”)
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
cmake/FindXKBCommon.cmake:30 (find_package_handle_standard_args)
CMakeLists.txt:43 (find_package)

– Configuring incomplete, errors occurred!
See also “/home/dell/fcitx-qt5/CMakeFiles/CMakeOutput.log”.

解决Ubuntu下的qtcreator不能输入中文的问题_第2张图片
解决方法:下载libxkbcommon-0.5.0.tar.xz,并编译安装。
下载网址:http://xkbcommon.org/download/libxkbcommon-0.5.0.tar.xz

 tar xvf libxkbcommon-0.5.0.tar.xz
 cd libxkbcommon-0.5.0
 sudo ./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --disable-x11
 sudo make
 sudo make install

在使用sudo make编译时,会出现如下问题,可通过安装bison解决------ sudo apt-get install bison解决Ubuntu下的qtcreator不能输入中文的问题_第3张图片
3.在fcitx-qt5目录下make时,无法正常编译。
In file included from /usr/include/fcitx-utils/utils.h:67:0,
from /usr/include/fcitx-config/xdg.h:37,
from /home/dell/fcitx-qt5/qt5/quickphrase-editor/filelistmodel.cpp:22:
/home/dell/fcitx-qt5/qt5/quickphrase-editor/filelistmodel.cpp: In member function ‘void fcitx::FileListModel::loadFileList()’:
/home/dell/fcitx-qt5/qt5/quickphrase-editor/filelistmodel.cpp:65:5: error: ‘typeof’ was not declared in this scope
HASH_SORT(files, fcitx_utils_string_hash_set_compare);
^
/home/dell/fcitx-qt5/qt5/quickphrase-editor/filelistmodel.cpp:65:5: error: ‘typeof’ was not declared in this scope
HASH_SORT(files, fcitx_utils_string_hash_set_compare);
^
qt5/quickphrase-editor/CMakeFiles/fcitx-quickphrase-editor5.dir/build.make:194: recipe for target ‘qt5/quickphrase-editor/CMakeFiles/fcitx-quickphrase-editor5.dir/filelistmodel.cpp.o’ failed
make[2]: *** [qt5/quickphrase-editor/CMakeFiles/fcitx-quickphrase-editor5.dir/filelistmodel.cpp.o] Error 1
CMakeFiles/Makefile2:867: recipe for target ‘qt5/quickphrase-editor/CMakeFiles/fcitx-quickphrase-editor5.dir/all’ failed
make[1]: *** [qt5/quickphrase-editor/CMakeFiles/fcitx-quickphrase-editor5.dir/all] Error 2
Makefile:127: recipe for target ‘all’ failed
make: *** [all] Error 2

原因:上面下载的版本较新,选择旧一点的版本
下载网址:https://download.fcitx-im.org/fcitx-qt5/fcitx-qt5-1.1.1.tar.xz
然后解压,进入目录

cmake .
make
sudo make install

完美解决~ 在fcitx-qt5/platforminputcontext目录生成得到我们想要的libfcitxforminputcontextplugin.so文件

参考资料
1.https://blog.csdn.net/bootleader/article/details/116244041
2.https://blog.csdn.net/netyiming/article/details/79171157(重点fcitx-qt5版本问题)
3.https://www.jianshu.com/p/8ddbf9d6248a
4.https://www.linuxdiyf.com/linux/17179.html
5.https://www.cnblogs.com/oloroso/p/5114041.html
6.https://my.oschina.net/u/3579120/blog/1508413

你可能感兴趣的:(ubuntu,git,linux)