[解決方案] Ubuntu 16.04 下 Qt 5.6 無法輸入中文的問題


0. 環境

系統:ubuntu 16.04 LTS
機子:dell xps13

1. 步驟

1.1 編譯 fcitx-qt5 源碼

  1. 編譯fcitx-qt需要cmake,安裝cmake命令,如果已經安裝,請略過;
    sudo apt-get install cmake
  2. 安裝 fcitx-libs-dev;
    sudo apt-get install fcitx-libs-dev
  3. 設置qmake的環境變量,這一步很重要且環境變量的值因人而異
    3.1. 首先確定你的Qt的安裝目錄,我這里是~/software/Qt5.6.0/,你的或者可能在/home/<用戶名>/Qt5.6.0/
    3.2. export PATH="<Qt安裝目錄>/5.6/gcc_64/bin":$PATH
  4. 下載fcitx-libs 源碼
    4.1. 原文的 git clone git@github.com:fcitx/fcitx-qt5.git 不可行,需要修改為 https://github.com/fcitx/fcitx-qt5
    4.2. git clone https://github.com/fcitx/fcitx-qt5
  5. 編譯 fcitx-qt5
cd fcitx-qt5
cmake .
make 
sudo make install

1.2. 拷貝 so 文件

  1. 編譯完成后,需要把編譯得到的 libfcitxplatforminputcontextplugin.so 拷貝到 Qt5.5 安裝目錄的 Tools/QtCreator/bin/plugins/platforminputcontextsQt5.6 安裝目錄的 Tools/QtCreator/lib/Qt/plugins/platforminputcontexts,注意:兩個目錄根據你的Qt版本而定,Qt安裝目錄因人而異。
  2. 復制:
    Qt 5.5:cp platforminputcontext/libfcitxplatforminputcontextplugin.so <Qt安裝目錄>/Tools/QtCreator/bin/plugins/platforminputcontexts
    Qt 5.6:cp platforminputcontext/libfcitxplatforminputcontextplugin.so <Qt安裝目錄>/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts
    我這里是:cp platforminputcontext/libfcitxplatforminputcontextplugin.so ~/software/Qt5.6.0/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts

1.3 添加額外的環境變量

echo 'export XMODIFIERS=@im=fcitx' >> .bashrc 
echo 'export QT_IM_MODULE=fcitx' >> .bashrc

大功告成!

2. 遇到的問題

說明:本人系統為 Ubuntu 16.04 LTS 英文版 ,遇到的問題基本和原文一樣

2.1 安裝CMake失敗

  1. 問題描述:sudo apt-get install cmake 執行到 92 % 時提示下載失敗,原因是找不到 IP 地址。
  2. 問題解決:覺得應該是安裝包源的問題,於是修改了系統默認的源。
    System Settings -> Software & Updates -> Ubuntu Software -> Download from 從原來的 China 改為 Main server,最后再
    sudo apt-get update
    sudo apt-get install cmake

2.2 CMake 錯誤

  1. 問題描述:
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!
  1. 解決方法:
    2.1. 到這個頁面 https://launchpad.net/ubuntu/+source/extra-cmake-modules/1.4.0-0ubuntu1 下載 extra-cmake-modules_1.4.0.orig.tar.xz
    2.2. 解壓后編譯安裝
cd extra-cmake-modules-1.4.0
cmake .
make
sudo make install

2.3 安裝 extra-cmake-modules-1.4.0 失敗

  1. 問題描述:
$:~/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
-- Build files have been written to: /home/cposture/Downloads/extra-cmake-modules-1.4.0
  1. 解決方法:
    設置 CMAKE_PREFIX_PATH 環境變量 為 qtbase 目錄(<Qt安裝目錄>/5.6/Src/qtbase/),我這里為:
export CMAKE_PREFIX_PATH="~/software/Qt5.6.0/5.6/Src/qtbase/"

如果還是不行,則修改為

export CMAKE_PREFIX_PATH="/home/cposture/software/Qt5.6.0/5.6/gcc_64/lib/cmake/"

2.4 缺少 xkbcommon 包

  1. 問題描述:
 -- 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") 
  1. 解決方法:
    2.1. 到 http://xkbcommon.org/ 下載最新版的 xkbcommon
    2.2. 解壓后,
sudo apt-get install bison
./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --disable-x11
make
sudo make install

原文鏈接:http://www.cnblogs.com/cposture/p/5397694.html
參考:http://my.oschina.net/lieefu/blog/505363?p=1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM