Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间

上篇介绍了Ubuntu系统下搭建QtCreator开发环境。我们可以发现安装好的QtCreator不能输入中文,也没有中文输入法供选择,这里需要进行设置。

文章目录

  • 1. 配置软件源的服务器地址
  • 2. 先配置Ubuntu系统语言,设置为中文
  • 3. 安装Fcitx插件,指令如下
  • 4. 配置QtCreator输入中文
  • 5. 修改Ubuntu系统时间

1. 配置软件源的服务器地址

我们先配置软件源的服务器地址为阿里云的地址。这样我们可以从国内去获取软件源,下载速度会更快。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第1张图片
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第2张图片
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第3张图片
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第4张图片
更新完成后,界面消失。

在Ubuntu中更新,过程如下:

dawes@ubuntu:~$ sudo apt-get update
[sudo] password for dawes: 
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease               
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease             
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-security InRelease              
Reading package lists... Done  

2. 先配置Ubuntu系统语言,设置为中文

在 Ubuntu 右上角,点击设置图标如下图第①步。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第5张图片
按如下图设置, 点击(install/Remove Languages …) 安装或者移除语言,在安装语言处选择简体中文,点击 Apply 应用即可。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第6张图片
汉语(中国)拖到最前面,对应下图中的7,然后依照以下顺序执行。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第7张图片
配置完成后,点击重启(或者注销 Ubuntu)。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第8张图片

重启后,因为我们已经更新了系统的语言,Ubuntu 询问我们需不需要将系统文件夹的名称也改成中文。这里作者选择否,保留旧的名称。保留旧的名称有一定的好处,就是我们进入这些访目录时,直接使用英文,不用切换到中文输入法。 严格来说,最好是统一用英文环境开发了。这里为了初学者或者有强迫中文者,所以我们这里需要配置中文的环境,及后期开发 Qt 需要写中文注释,方便理解与给后人看。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第9张图片

3. 安装Fcitx插件,指令如下

在上面我们已经配置好中文环境,并有拼音输入法 ibus,但 ibus 并不好用, Qt Creator 不支持 ibus 输入中文。 好的生产工具决定好的生产力,下面我们介绍一下 Fcitx 输入法。

Fcitx (Flexible Input Method Framework) ──即小企鹅输入法,它是一个以 GPL 方式发布的输入法平台,可以通过安装引擎支持多种输入法,支持简入繁出,是在 Linux 操作系统中常用的中文输入法。它的优点是:短小精悍、跟程序的兼容性比较好。

Fcitx 内置的输入法支持中文 拼音 和基于字符表的输入(例如五笔),根据语言的不同,有不同的输入法引擎可以选择。
在 Fcitx 支持的拼音输入法中,内置拼音响应速度最快。Fcitx 同样支持流行的第三方拼音输入法以提供更好的整句输入效果。

  • fcitx-sunpinyin 在输入速度和输入精度之间有较好的平衡。
  • …其他详见介绍资料

安装 Fcitx 输入法,下面主要介绍两种输入法(五笔输入法与拼音输入),本次以安装拼音输入法为例。

sudo apt-get install fcitx-sunpinyin

按照提示进行操作。

再到右上角点击系统设置,找到语言支持,将键盘输入方式系统点击下拉复选框选择为 fcitx,然后点击应用到整个系统,再关闭。 如下图步骤。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第10张图片
为了确保刚配置的环境生效, 完成以上步骤后重启 Ubuntu 系统。

Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第11张图片
将“Sunpinyin”置顶
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第12张图片
至此完成Ubuntu系统中文输入法的安装,使用"ctrl+空格"可以实现中英文输入法的切换。

4. 配置QtCreator输入中文

打开QtCreator可以看到,即使使用"ctrl+空格"还是无法输入中文。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第13张图片

sudo apt install fcitx-frontend-qt5

安装插件,在上步安装fcitx时就已经安装好,显示如下:

dawes@ubuntu:~$ sudo apt install fcitx-frontend-qt5
[sudo] dawes 的密码: 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
fcitx-frontend-qt5 已经是最新版 (1.1.1-1build3)。
fcitx-frontend-qt5 已设置为手动安装。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 54 个软件包未被升级。

将插件拷到到Qt的安装目录,命令如下:

sudo cp /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so /opt/Qt5*/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts

过程如下:

dawes@ubuntu:~$ ls /opt/Qt5*/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts
libcomposeplatforminputcontextplugin.so  libibusplatforminputcontextplugin.so
dawes@ubuntu:~$ ls /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so  libibusplatforminputcontextplugin.so
libfcitxplatforminputcontextplugin.so
dawes@ubuntu:~$ sudo cp /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so /opt/Qt5*/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts
dawes@ubuntu:~$ ls /opt/Qt5*/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts
libcomposeplatforminputcontextplugin.so  libibusplatforminputcontextplugin.so
libfcitxplatforminputcontextplugin.so

此时还不能输入中文,关闭Qt进行重启

重新打开 Qt Creator 方可输入中文!如下图。需要按 Ctrl+Space(空格键)激活输入法。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第14张图片
至此,在QtCreator中可以输入中文。

5. 修改Ubuntu系统时间

可以看到Ubuntu的时间是与实际不符的,需要修改时区。
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第15张图片
具体操作如下:

dawes@ubuntu:~$ tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
 1) Africa
 2) Americas
 3) Antarctica
 4) Asia
 5) Atlantic Ocean
 6) Australia
 7) Europe
 8) Indian Ocean
 9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the time zone using the Posix TZ format.
#? 4
Please select a country whose clocks agree with yours.
 1) Afghanistan		     29) Kyrgyzstan
 2) Antarctica		     30) Laos
 3) Armenia		     31) Lebanon
 4) Azerbaijan		     32) Macau
 5) Bahrain		     33) Malaysia
 6) Bangladesh		     34) Mongolia
 7) Bhutan		     35) Myanmar (Burma)
 8) Brunei		     36) Nepal
 9) Cambodia		     37) Oman
10) China		     38) Pakistan
......
#? 10
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time, Vostok
#? 1

The following information has been given:

	China
	Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Selected time is now:	Thu Aug 31 21:25:54 CST 2023.
Universal Time is now:	Thu Aug 31 13:25:54 UTC 2023.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
	TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
dawes@ubuntu:~$ vi .profile

TZ='Asia/Shanghai'; export TZ写入到最后一行
Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第16张图片

  • :wq保存退出,vim的一些基本的操作可以参考:文本编辑器Vim常用操作和技巧

  • 进行同步

dawes@ubuntu:~$ sync
  • 注销账号,重新登录
    Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第17张图片
  • 登录后发现,时间已经和实际时间一致
    Ubuntu系统下配置 Qt Creator 输入中文、配置软件源的服务器地址、修改Ubuntu系统时间_第18张图片

对应地址:配置Ubuntu下Qt Creator中文输入

你可能感兴趣的:(#,嵌入式Linux,Qt5(C++)开发,linux,qt5)