Ubuntu安装QT5

前言

最近打算学一下QT应用程序开发,所以打算装一个QT桌面环境QtCreator,捣鼓了一阵,把电脑弄坏重装系统之后,终于安装好了,这里分享一下安装的过程

1. QT5安装

环境

Ubuntu14.04
QT5.12.3
  • 1
  • 2

首先去QT安装包下载安装包,我这里选择的是目前最新的QT5.12.3
QT安装包
下载好之后赋予可执行权限

chmod +x qt-opensource-linux-x64-5.12.3.run
  • 1

然后执行安装命令

sudo ./qt-opensource-linux-x64-5.12.3.run
  • 1

然后一直点下一步或者跳过就好了,安装路径我也是默认的
QT安装路径
等待安装完成

2. 路径配置

安装完成之后,需要修改default.conf,执行

sudo vim /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf
  • 1

将第一行改为自己安装路径下的bin目录的路径,第二行改为Qt5.12.3目录的路径,下面是我的配置

/opt/Qt5.12.3/5.12.3/gcc_64/bin
/opt/Qt5.12.3/
  • 1
  • 2

3. 运行问题

3.1 FT_Get_Font_Format

运行qtcreator,然后报错undefined symbol: FT_Get_Font_Format

anruliu@anruliu:/opt/Qt5.12.3/Tools/QtCreator/bin$ ./qtcreator
./qtcreator: symbol lookup error: /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/plugins/platforms/../../lib/libQt5XcbQpa.so.5: undefined symbol: FT_Get_Font_Format
  • 1
  • 2

需要下载安装freetype-2.10.0,解压之后执行

cd freetype-2.10.0
./configure --prefix=/opt/Qt5.12.3/Tools/QtCreator/lib/Qt/
make
cd ./objs/.libs
sudo cp libfreetype.so /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib
sudo cp libfreetype.so.6 /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib
sudo cp libfreetype.so.6.17.0 /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

其中/opt/Qt5.12.3/就是安装QT的目录

3.2 LIBDBUS_1_3 not defined

再次运行qtcreator,然后报错version LIBDBUS_1_3 not defined

anruliu@anruliu:/opt/Qt5.12.3/Tools/QtCreator/bin$ ./qtcreator
./qtcreator: relocation error: /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/plugins/platforms/../../lib/libQt5DBus.so.5: symbol dbus_message_get_allow_interactive_authorization, version LIBDBUS_1_3 not defined in file libdbus-1.so.3 with link time reference
  • 1
  • 2

需要下载安装dbus-1.13.10,解压之后执行

cd dbus-1.13.10
./configure --prefix=/opt/Qt5.12.3/Tools/QtCreator/lib/Qt/
make
cd ./dbus/.libs
sudo cp libdbus-1.so /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib
sudo cp libdbus-1.so.3 /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib
sudo cp libdbus-1.so.3.26.0 /opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

其中/opt/Qt5.12.3/就是安装QT的目录
把缺失的库直接拷贝到qtcreator的lib的路径下,可以让qtcreator找到它自己需要依赖的库,不会对系统本身造成影响,不然可能会导致桌面起不来,然后得重装系统

所有问题解决后,运行qtcreator,就可以看到界面,可以尽情的开发了
qtcreator运行效果

4. 编译应用问题

在示例中选择一个demo进行编译,比如我选的是shadow-map-qml,在构建设置配置好后,点击运行,发现还有一些错误

4.1 GL/gl.h: No such file or directory

/opt/Qt5.12.3/5.12.3/gcc_64/include/QtGui/qopengl.h:144: error: GL/gl.h: No such file or directory
  • 1

需要安装gl的库

sudo apt-get install libgl1-mesa-dev
  • 1

4.2 LIBDBUS_1_3 not defined

relocation error: /opt/Qt5.12.3/5.12.3/gcc_64/lib/libQt5DBus.so.5: symbol dbus_message_get_allow_interactive_authorization, version LIBDBUS_1_3 not defined in file libdbus-1.so.3 with link time reference
  • 1

这个和运行qtcreator的错误一样,需要我们指定libdbus的目录,在项目–>构建设置–>构建环境添加环境变量LD_LIBRARY_PATH为/opt/Qt5.12.3/Tools/QtCreator/lib/Qt/lib,如下图所示
构建设置
改好之后,重新运行,就可以看到应用运行效果了!!!
QT DEMO

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值