1. 程式人生 > >解決Qt5.6無法使用輸入法輸入中文

解決Qt5.6無法使用輸入法輸入中文

最近在ubantu上使用Qt開發進行開發,遇到不能使用輸入法輸入中文的問題,有點頭疼,於是百度谷歌雙管齊下,查閱各方資料,綜合各種解決方案,kill 了這個問題,在此做下筆記,也希望能夠幫助到同樣遇到此問題的人。

系統版本: ubantu 16.04 LTS

輸入法: 搜狗輸入法

本人Qt版本: Qt5.6

解決方法,編譯 fcitx-qt5 原始碼

一、解決步驟

1.1 前期準備工作

(1).安裝cmake

sudo apt-get install cmake

(2) 安裝 fcitx-libs-dev

sudo apt-get install fcitx-libs-dev

(3) 設定環境變數

export PATH="/home/ProgramFiles/Qt5.6.1/5.6/gcc_64/bin":$PATH

其中藍色部分為安裝Qt的位置,,這個根據個人的安裝位置情況而定.

(4) 下載 fcitx-qt5 原始碼

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

如果顯示沒有許可權獲取,及表明沒有祕鑰,則可以開啟這個網址直接到github上去下載壓縮包,再解壓即可.

1.2 執行編譯操作

編譯 fcitx-qt5

 cd fcitx-qt5

 cmake .

 make

 sudo make install

1.3 拷貝編譯得到的 so 檔案

編譯成功之後,將編譯得到的libfcitxplatforminputcontextplugin.so 檔案拷貝到Qt的按裝目錄下

Tools/QtCreator/bin/plugins/platforminputcontexts 或Tools/QtCreator/lib/Qt/plugins/platforminputcontext

之中,兩個目錄由安裝情況而定,有的會是第一個路徑,有的則是第二個路徑,然後再繼續將這個文

件放在Qt5.6.1/5.6/gcc_64/plugins/platforminputcontexts之下 最後重啟Qt或則重啟電腦則可以了.

二、在此過程中可能遇到的問題

2.1 缺少 ECMConfig.cmake 和ecm-config.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.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!

下載 extra-cmake-modules_1.4.0.orig.tar.xz

解壓後進行如下操作:

cd  extra-cmake-modules-1.4.0

cmake .

sudo make install

2.2 缺少Qt5Config.cmake 和qt5-config.cmake

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.

設定 CMAKE_PREFIX_PATH 環境變數

export CMAKE_PREFIX_PATH="/home/cc/ProgramFiles/Qt5.6.1/5.6/gcc_64/lib/cmake/"

2.3 缺少 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 libxkcommon-dev 

編譯:

sudo apt-get install bison

./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu --disable-x11

make

sudo make install

三、其他參考資料