ubuntu安装Qt

一、安装

卸载旧版本Qt,找到安装目录,例如:/home/likewei/Qt5.11.2,终端输入命令进入该目录,输入命令:./MaintenanceTool      进入图形画面卸载就行了

1.下载安装文件,如:qt-opensource-linux-x64-5.11.2.run

2.打开终端(快捷键ctrl+alt+t),使安装文件可以执行,在当前目录输入命令 sudo chmod u+x qt-opensource-linux-x64-5.11.2.run

3.可以点击qt-opensource-linux-x64-5.11.2.run 安装。

4.apt-get安装源替换 阿里云源,否则安装的时候会出现“破坏了软件包间的依赖关系”等等错误。

编辑sources.list

sudo vim /etc/apt/sources.list

用下面的文本作为内容替换sources.list内容

ubuntu 14

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

ubuntu 16

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##测试版源
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# 源码
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##测试版源
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# Canonical 合作伙伴和附加
deb http://archive.canonical.com/ubuntu/ xenial partner
deb http://extras.ubuntu.com/ubuntu/ xenial main

5.输入命令安装g++, sudo apt-get install g++

默认ubuntu14的gcc版本是4.8,支持c++11, 不支持c++14,安装g++ 5

5.1添加库

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

5.2 更新库

sudo apt-get update

5.3 安装

sudo apt-get install gcc-5 g++-5

5.4换软连接

sudo ln -s /usr/bin/gcc-5 /usr/bin/gcc -f
        sudo ln -s /usr/bin/gcc-ar-5 /usr/bin/gcc-ar -f
        sudo ln -s /usr/bin/gcc-nm /usr/bin/gcc-nm -f
       sudo ln -s /usr/bin/g++-nm /usr/bin/g++-nm -f
       sudo ln -s /usr/bin/g++-ar-5 /usr/bin/g++-ar -f
       sudo ln -s /usr/bin/g++-5 /usr/bin/g++ -f

再查看版本 gcc -v

6.如果系统没有安装vim,输入命令安装,sudo apt-get install vim-gtk

7.输入qmake会出错:qmake:could not exec ‘/usr/lib/x86_64-linux-gnu/qt4/bin/qmake’:NO such file or directory(32位的ubuntu报的是这样的错 qmake:could not exec ‘/usr/lib/i386-linux-gnu/qt4/bin/qmake’:NO such file or directory)

修改文件:输入 sudo vim  /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

修改前两行,根据qt安装文件路径修改成:

/home/likewei/Qt5.11.2/5.11.2/gcc_64/bin

/home/likewei/Qt5.11.2/5.11.2/gcc_64

vim编辑备忘:输入i进入插入模式,移动鼠标删除,编辑。输入esc退出当前模式,输入:进入命令模式。:w保存。

8.安装libgl1-mesa-dev ,否则在编译时会出错,提示

  cannot find -lGL
collect2:error:ld returned 1 exit status
  sudo apt-get install libgl1-mesa-dev 其他:
安装jsoncpp:
sudo apt-get install libjsoncpp-dev 二、ubuntu建立qt的默认打开方式
设置pro文件默认打开方式为qtcreator的方法如下:
1.建立软链接
sudo ln -s /home/likewei/Qt5.12.1/Tools/QtCreator/bin/qtcreator /usr/local/bin/qtcreator
如果已经建立了加参数-f,-f 建立时,将同档案名删除.
 sudo ln -s -f /home/likewei/Qt5.12.1/Tools/QtCreator/bin/qtcreator /usr/local/bin/qtcreator
2.建立qtcreator.desktop
sudo vim /usr/share/applications/qtcreator.desktop
复制以下内容,修改图标位置,可以在网上下载一个图标:         
[Desktop Entry]
Name = Qt Creator
Comment = Open qt pro file
Exec = qtcreator %U
Terminal = false
StartupNotify = true
X-MultipleArgs = false
Type = Application
Categories = Utility;
Icon = /home/likewei/图片/appimg/Qt.png

Icon=// 软件图标位置,可以自己选一个png图像,把png图像的绝对路径放这就可以

三、解决Qt不能输入中文注释问题

在/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so  找到libfcitxplatforminputcontextplugin.so 。把此库文件复制到

以下Qt安装文件两个目录下面。

/home/likewei/Qt5.12.1/5.12.1/gcc_64/plugins/platforminputcontexts
/home/likewei/Qt5.12.1/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts

上一篇:http和websocket共用同一端口


下一篇:代码配置没有问题,为什么不回滚事务(要理解Mysql数据库引擎)