解決 QtCreator 3.5(4.0)無法輸入中文的問題


解決 QtCreator 3.5.1無法輸入中文的問題

環境是ubuntu 15.10
ubuntu軟件源中下載安裝的fctix-libs-qt5現在沒有用,版本太舊了。
自己下載fctix-qt5的源碼來編譯即可。

1、獲取fctix-qt5源碼

我沒有找到fcitx-qt5git倉庫地址,只找到了源碼包的下載地址。

先下載源碼包,並解壓。

wget https://download.fcitx-im.org/fcitx-qt5/fcitx-qt5-1.0.5.tar.xz
tar -xJf fcitx-qt5-1.0.5.tar.xz

找到了git倉庫地址

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

2、生成Makefile文件

這一步很簡單,進入源碼目錄,然后新建一個build的目錄並進入,然后使用cmake來生成Makefile

cd fcitx-qt5
mkdir build && cd build
cmake ..

這一個步驟產生了幾個錯誤,這和系統環境有關。如果你的沒有產生錯誤,后面就不用看了

2.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 "/home/o/fcitx/fcitx-qt5/CMakeFiles/CMakeOutput.log".

解決辦法
先下載cmake的擴展模塊包

wget https://launchpadlibrarian.net/189487929/extra-cmake-modules_1.4.0.orig.tar.xz
tar -xJf extra-cmake-modules_1.4.0.orig.tar.xz

進入其中,然后執行cmake .來生成Makefile文件
這一步需要指定兩個變量

//The directory containing a CMake configuration file for Qt5Core.
Qt5Core_DIR:PATH=/home/o/program/qt_5.5/qt_5.5.1_x64/5.5/gcc_64/lib/cmake/Qt5Core

//The directory containing a CMake configuration file for Qt5LinguistTools.
Qt5LinguistTools_DIR:PATH=/home/o/program/qt_5.5/qt_5.5.1_x64/5.5/gcc_64/lib/cmake/Qt5LinguistTools

2016年08月17日更新
上面一步其實直接指定Qt_DIR目錄也就可以了。

#只需要指定Qt5_DIR路徑即可
cmake -DQt5_DIR=/home/o/pragram/qt_5.7/5.7/gcc_64/lib/cmake/Qt5 .

生成了Makefile之后,直接sudo make install來安裝就可以了。

2.2、找不到Qt5包配置文件的錯誤

報錯信息

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!
See also "/home/o/fcitx/fcitx-qt5/build/CMakeFiles/CMakeOutput.log".

這個錯誤很好解決,設置變量Qt5_DIR即可

cmake -DQt5_DIR=/home/o/program/qt_5.5/qt_5.5.1_x64/5.5/gcc_64/lib/cmake/Qt5 ..

2.3、libxkbcommon問題

錯誤信息

o@o-pc:~/fcitx/fcitx-qt5/build$ cmake -DQt5_DIR=/home/o/program/qt_5.5/qt_5.5.1_x64/5.5/gcc_64/lib/cmake/Qt5  ..
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.28") 
-- Found XKBCommon_XKBCommon: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (found version "0.5.0") 
-- Found XKBCommon: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (found suitable version "0.5.0", minimum required is "0.5.0") found components:  XKBCommon 
-- checking for module 'fcitx-utils'
--   package 'fcitx-utils' not found
CMake Error at /usr/share/cmake-3.2/Modules/FindPkgConfig.cmake:344 (message):
  A required package was not found
Call Stack (most recent call first):
  /usr/share/cmake-3.2/Modules/FindPkgConfig.cmake:506 (_pkg_check_modules_internal)
  CMakeLists.txt:32 (pkg_check_modules)


-- Configuring incomplete, errors occurred!
See also "/home/o/fcitx/fcitx-qt5/build/CMakeFiles/CMakeOutput.log".

這個問題的解決如下
先下載libxkbcommon-0.5.0.tar.xz,然后解壓編譯

http://xkbcommon.org/download/libxkbcommon-0.5.0.tar.xz
tar -xJf libxkbcommon-0.5.0.tar.xz

這個使用./configure --disable-x11來生成Makefile。禁用x11是因為我機器上的x11版本過高的原因。

編譯的時候可能會報錯

 make
  YACC     src/xkbcomp/parser.c
./build-aux/ylwrap: 行 176: yacc: 未找到命令
Makefile:1522: recipe for target 'src/xkbcomp/parser.c' failed
make: *** [src/xkbcomp/parser.c] Error 127

需要yacc的支持。這個工具包含在軟件包bison中。

o@o-pc:~/fcitx/libxkbcommon-0.5.0$ sudo apt-get install bison

然后直接make && make install安裝就是。

2.4、'fcitx-utils' not found錯誤

這個錯誤是因為我們沒有安裝fcitx-libs-dev的緣故,所以解決的辦法就是安裝它就是。
錯誤信息

o@o-pc:~/fcitx/fcitx-qt5/build$ cmake -DQt5_DIR=/home/o/program/qt_5.5/qt_5.5.1_x64/5.5/gcc_64/lib/cmake/Qt5  ..
-- checking for module 'fcitx-utils'
--   package 'fcitx-utils' not found
CMake Error at /usr/share/cmake-3.2/Modules/FindPkgConfig.cmake:344 (message):
  A required package was not found
Call Stack (most recent call first):
  /usr/share/cmake-3.2/Modules/FindPkgConfig.cmake:506 (_pkg_check_modules_internal)
  CMakeLists.txt:32 (pkg_check_modules)

-- Configuring incomplete, errors occurred!

解決辦法

sudo apt-get install fcitx-libs-dev 

3、編譯出動態庫

經過上面的步驟,生成了Makefile文件后,接下來的步驟就很簡單了,直接make來編譯即可。

 make
Scanning dependencies of target FcitxQt5DBusAddons_automoc
[  4%] Automatic moc for target FcitxQt5DBusAddons
... ... 中間步驟省略
Linking CXX shared module libfcitxplatforminputcontextplugin.so
[100%] Built target fcitxplatforminputcontextplugin

進入構建目錄下的platforminputcontext目錄,即可看到生成的libfcitxplatforminputcontextplugin.so文件
將其拷貝到QtCreator安裝目錄下的..../QtCreator/bin/plugins/platforminputcontexts目錄下即可。

2016年08月17日更新
QtCreator 4.0的目錄結構有一點小變化,需要將其拷貝到QtCreator目錄下的QtCreator/lib/Qt/plugins/platforminputcontexts目錄中。

o@o-pc:~/fcitx/fcitx-qt5/build/platforminputcontext$ ls
CMakeFiles  cmake_install.cmake  fcitxplatforminputcontextplugin_automoc.cpp  libfcitxplatforminputcontextplugin.so  Makefile  moc_main.cpp  moc_qfcitxplatforminputcontext.cpp
cp libfcitxplatforminputcontextplugin.so /home/o/program/qt_5.5/qt_5.5.1_x64/Tools/QtCreator/bin/plugins/platforminputcontexts/

輸入中文示例


免責聲明!

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



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