在Ubuntu下安装qt

安装qt前的准备:

安装基础开发包,主要gcc,g++等:

sudo apt-get install build-essential

1. 使用qt-opensource-linux-x86-5.5.1.run来安装:https://blog.csdn.net/hansion3333/article/details/60468590

在一个小机器上运行(该机器开机时没有界面),显示错误QXcbConnection: Could not connect to display :0.0


2.使用源码qt-everywhere-opensource-src-xxx.tar.gz来安装:

https://blog.csdn.net/hansion3333/article/details/60468590

https://blog.csdn.net/lh2016rocky/article/details/70174715

看看下面的:

https://blog.csdn.net/LEON1741/article/details/56681718

https://blog.csdn.net/LEON1741/article/details/58587274?locationNum=8&fps=1

文件下载:http://download.qt.io/official_releases/qt/5.7/5.7.1/single/,或者http://download.qt.io/archive/qt/5.10/5.10.1/single/, 这类文件原来在single目录下(对于较高的版本是在single目录下的)。

1)在/home/username 中新建文件,命令 : mkdir qtSrc

2)把安装包解压到qtSrc文件夹中, 命令: tar zxvf qt-everywhere-opensource-src-xxx.tar.gz 

3)cd 到安装包里configure.exe文件所在的文件夹中,输入配置命令 

./configure

 add1: 如果出现没有g++错误,输入命令:sudo apt-get install g++    (注:等待20分钟左右)再运行 ./configure –prefix .

add2: 可以运行 ./configure -help,查看安装选项说明,例如:

-prefix <dir> ...... The deployment directory, as seen on the target device.

                         (default /usr/local/Qt-5.7.1, $PWD if -developer-build is active)

  add3: 我遇到问题:

        The test for linking against libxcb and support libraries failed!You might need to install dependency packages, or pass -qt-xcb.        See src/plugins/platforms/xcb/README.

提示看README文件,提示的src文件在解压缩的目录下!该文件中提到:

"Requires libxcb >= 1.5.

PACKAGE DEPENDENCIES

Required packages:
libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm1 libxcb-icccm1-dev libxcb-sync0 libxcb-sync0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev libxcb-xinerama0-dev

On Ubuntu 11.10 icccm1 is replaced by icccm4 and xcb-render-util is not available:
libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev libxcb-xinerama0-dev
The packages for xcb-render-util can be installed manually from http://packages.ubuntu.com/natty/libxcb-render-util0 and http://packages.ubuntu.com/natty/libxcb-render-util0-dev

On Ubuntu 12.04 icccm1 is replaced by icccm4 and xcb-render-util can be installed automatically:
libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-glx0-dev libxcb-xinerama0-dev

On Fedora, the following packages are required:
libxcb libxcb-devel libXrender libXrender-devel xcb-util-wm xcb-util-wm-devel xcb-util xcb-util-devel xcb-util-image xcb-util-image-devel xcb-util-keysyms xcb-util-keysyms-devel

REDUCING RUNTIME DEPENDENCIES

The '-qt-xcb' configure option can be used to get rid of most xcb- dependencies. Only libxcb will
still be linked dynamically, since it will be most likely be pulled in via other dependencies anyway.
This should allow for binaries that are portable across most modern Linux distributions. "

网上说直接安装上面红色的库,sudo apt-get install ibxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-glx0-dev libxcb-xinerama0-dev

但是,提示错误,网上说原因时:没有运行sudo apt-get update,但是我运行update也出错了! stop here!

///////////////////////////////////////////////////////////////////////////////////////////

源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install),具体的安装方法一般作者都会给出文档,这里主要讨论配置(configure)。Configure是一个可执行脚本,它有很多选项,使用命令./configure –help输出详细的选项列表,如下:

Usage: configure [options] [host]
Options: [defaults in brackets after descriptions]
Configuration:
...........
--help             print this message
--no-create         do not create output files
Directory and file names:
--prefix=PREFIX       install architecture-independent files in PREFIX
                [/usr/local]
--exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                [same as prefix]
--bindir=DIR         user executables in DIR [EPREFIX/bin]

……….(省略若干)

很多的选项,个人认为,你可以忽略其他的一切,但请把—prefix加上。这里以安装supersparrow-0.0.0为例,我们打算把它安装到目录 /usr/local/supersparrow,于是在supersparrow-0.0.0目录执行带选项的脚本./configure --prefix=/usr/local/supersparrow,执行成功后再编译、安装(make,make install);安装完成将自动生成目录supersparrow,而且该软件所有的文件都被复制到这个目录。为什么要指定这个安装目录?是为了以后的维护方便,如果没有用这个选项,安装过程结束后,该软件所需的软件被复制到不同的系统目录下,很难弄清楚到底复制了那些文件、都复制到哪里去了—基本上是一塌糊涂。
用了—prefix选项的另一个好处是卸载软件或移植软件。当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。

上一篇:Database学习 - mysql 连接数据库 库操作


下一篇:【转载】Ubuntu环境下安装QT(转)