Linux下QtCreator和应用输入中文

原先在Debian系下的Qtcreator无法输入中文时,可以直接在软件源下载fcitx-libs-qtfcitx-libs-qt5,然后复制到相应的目录下即可实现输入中文,但是现在Qtcreator已经发布了很多新版本了,软件园的fcitx已经太旧,下载下来也没有什么用了。所以得自己编译最新的的版本才能让Qtcreator支持中文。

系统环境介绍

我的系统是Deepin 15.11Qt 5.12.3QtCreator 4.9(base on 5.12.2)

操作方法

1. 安装fcitx-libs-dev
sudo apt-get install fcitx-libs-dev

不装这个会出现'fcitx-utils' not found错误

2. 设置qmake环境

这里需要找到你自己的安装目录

export PATH="~/Qt5.12.3/5.12.3/gcc_64/bin":$PATH
3. 下载fcitx-qt5源码并解压
wget https://download.fcitx-im.org/fcitx-qt5/fcitx-qt5-1.0.5.tar.xz
tar -xJf fcitx-qt5-1.0.5.tar.xz
4. 编译安装

这里如果一次没出问题,那运气不错,直接下一步。

cd fcitx-qt5-1.2.3
cmake .
make 
sudo make install
5. 拷贝so文件
  • 为了使Qtcreator能够输入中文,将编译好的so文件放在以下目录
~/Qt5.12.3/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts
  • 为了使Qtcreator开发的程序能够输入中文,要将so放在以下目录
~Qt5.12.3/5.12.3/gcc_64/plugins/platforminputcontexts

错误解决

编译fcitx-qt5会遇到一箩筐的问题,这里记录下我遇到的问题

1. 找不到ECM 包配置文件
cmake ..
-- The C compiler identification is GNU 5.2.1
-- The CXX compiler identification is Clang 3.7.0
... ...
-- Detecting CXX compile features - done
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 "~/fcitx/fcitx-qt5/CMakeFiles/CMakeOutput.log".

这里的提示说明,需要1.4.0版本的ECM配置文件,所以到下面的网址下载并安装这个东西即可。但是安装这个东西有可能也安装不成,还需要下一步来解决

wget https://launchpad.net/ubuntu/+source/extra-cmake-modules/1.4.0-0ubuntu1 
cd extra-cmake-modules-1.4.0
cmake .
make
sudo make install
1.1 安装 extra-cmake-modules-1.4.0 失败
$:~/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

这里的解决方案比较简单,设置CMAKE_PREFIX_PATH的值为Qt自带的cmake目录即可

export CMAKE_PREFIX_PATH="~/Qt5.12.3/5.12.3/gcc_64/lib/cmake/"

这里设置完了就可以返回去重新编译安装 extra-cmake-modules-1.4.0

1.2 缺乏Qt5所提供的配置文件
-- Performing Test SUPPORT_CXX11
-- Performing Test SUPPORT_CXX11 - Success
CMake Error at CMakeLists.txt:29 (find_package):
  Could not find a package configuration file provided by "Qt5" (requested
  version 5.1.0) with any of the following names:

    Qt5Config.cmake
    qt5-config.cmake

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

-- Configuring incomplete, errors occurred!

这个问题的解决方法同1.1的方法一样

2. 缺少xkbcommon
-- 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") 

这个问题的修改需要额外额外额外注意,系统一般是已经带有这个包的了,如果按网上的方法去编译安装新的包,一顿操作猛如虎下去,会替换掉系统的包。最后的结果就是桌面环境崩溃。
网上提供的解决方案如下

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

安装bison的原因是需要用到YACC命令,然后因为系统的X11版本较高,所以得得禁用掉。我在桌面环境崩溃之后,在命令行中用旧版本的xkbcommon替换/usr/lib/x86_64-linux-gnu目录下的新装上的,然后在修改头文件。就可以恢复了,但是这个方法太粗暴了。

你可能感兴趣的:(Qt,Linux)