[解决方案] 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="/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 /Tools/QtCreator/bin/plugins/platforminputcontexts
    Qt 5.6:cp platforminputcontext/libfcitxplatforminputcontextplugin.so /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

转载于:https://www.cnblogs.com/cposture/p/5397694.html

<think>我们正在Ubuntu 16.04系统上安装Qt 5.7.7,并且有27个分卷压缩文件(从ubuntu16.04-Qt5.7.7z.001到ubuntu16.04-Qt5.7.7z.027)。我们需要将这些分卷文件合并并解压安装。 步骤: 1. 确保所有分卷文件都在同一个目录下,并且文件名连续正确。 2. 安装必要的工具(如果尚未安装)来处理7z分卷压缩文件。 3. 使用7z工具合并并解压分卷文件。 4. 安装Qt 5.7.7。 详细步骤: 步骤1:确认分卷文件完整 将所有的分卷文件(共27个)放在同一个目录下,例如~/Downloads/qt5.7.7。 步骤2:安装p7zip-full 在Ubuntu中,我们可以通过apt安装7z工具: ```bash sudo apt update sudo apt install p7zip-full ``` 步骤3:合并并解压分卷文件 进入分卷文件所在的目录,然后使用7z命令解压。由于分卷文件是以.7z.001、.7z.002等结尾的,我们可以使用以下命令: ```bash 7z x ubuntu16.04-Qt5.7.7z.001 ``` 注意:只需要指定第一个分卷文件,7z会自动识别并合并后续分卷。 步骤4:等待解压完成 解压后,你会得到一个完整的Qt安装目录。 步骤5:运行安装程序 进入解压后的目录,通常里面会有一个安装脚本(可能是.run文件)或者直接是Qt的安装文件。假设解压后得到一个.run文件,我们可以运行: ```bash chmod +x qt-installer.run # 如果文件没有执行权限,需要添加 ./qt-installer.run ``` 然后按照图形安装程序的指引进行安装。 注意:如果安装包不是可执行文件,而是已经编译好的Qt库,那么可能不需要运行安装程序,只需要将解压后的目录放在合适的位置,然后在Qt Creator中设置该路径即可。 步骤6:配置环境(可选) 如果需要,可以将Qt的bin目录添加到PATH环境变量中。例如,如果安装到/opt/Qt5.7.7/,则可以将以下内容添加到~/.bashrc中: ```bash export PATH=/opt/Qt5.7.7/Tools/QtCreator/bin:$PATH ``` 注意:以上步骤假设分卷压缩文件是完整的,并且没有损坏。如果解压过程中出现错误,需要重新下载损坏的分卷。 引用说明: 在安装过程中,我们使用了apt命令来安装依赖工具,这参考了Ubuntu包管理的一般做法[^3]。而分卷压缩文件的解压方法则是7z工具的常规用法。 相关问题: 1. 如何验证分卷压缩文件的完整性? 2.Ubuntu中如何设置Qt Creator的环境变量? 3. Qt 5.7.7在Ubuntu 16.04上的兼容性如何?</think>### Ubuntu 16.04安装Qt 5.7.7分卷压缩文件指南 #### 步骤1:合并分卷文件 1. **确认所有分卷完整** 确保27个分卷文件(`ubuntu16.04-Qt5.7.7z.001` 到 `ubuntu16.04-Qt5.7.7z.027`)在同一目录下,无缺失或重命名错误。 2. **安装7z解压工具** ```bash sudo apt update sudo apt install p7zip-full # 提供7z命令支持[^3] ``` 3. **合并并解压文件** 在分卷文件目录执行: ```bash 7z x ubuntu16.04-Qt5.7.7z.001 # 自动识别后续分卷 ``` 解压后得到完整Qt安装包(通常是`.run`文件或目录)。 #### 步骤2:安装Qt 5.7.7 1. **赋予执行权限** ```bash chmod +x qt-opensource-linux-x64-5.7.7.run # 替换为实际文件名 ``` 2. **图形化安装** ```bash ./qt-opensource-linux-x64-5.7.7.run ``` - 选择安装路径(建议默认`/opt/Qt5.7.7`) - 勾选所需组件(至少选择`Desktop gcc`) - 接受许可协议完成安装 3. **终端安装(无图形界面时)** ```bash ./qt-opensource-linux-x64-5.7.7.run --script script.qs # 需提前配置脚本 ``` #### 步骤3:配置环境 ```bash # 添加Qt Creator到PATH echo 'export PATH="$PATH:/opt/Qt5.7.7/Tools/QtCreator/bin"' >> ~/.bashrc source ~/.bashrc ``` #### 验证安装 ```bash qtcreator --version # 应显示Qt Creator 4.3.1 (基于Qt 5.7.7) ``` #### 常见问题解决 - **分卷损坏**: 用`7z t ubuntu16.04-Qt5.7.7z.001`校验完整性,重新下载损坏分卷。 - **依赖缺失**: 安装基础库: ```bash sudo apt install libgl1-mesa-dev libxcb-xinerama0 ``` - **权限问题**: 解压时用`sudo 7z x ...`,但建议用普通用户安装到`~/Qt`目录。 > 提示:Qt 5.7.7在Ubuntu 16.04兼容性良好,但需注意GCC版本应为5.4[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值