Ubuntu安装QT5

前言

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

1. QT5安装

环境

Ubuntu14.04
QT5.12.3

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

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

然后执行安装命令

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

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

2. 路径配置

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

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

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

/opt/Qt5.12.3/5.12.3/gcc_64/bin
/opt/Qt5.12.3/

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

需要下载安装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

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

3.2 LIBDBUS_1_3 not defined

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

扫描二维码关注公众号,回复: 9219120 查看本文章
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

需要下载安装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

其中/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

需要安装gl的库

sudo apt-get install libgl1-mesa-dev

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

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

发布了30 篇原创文章 · 获赞 28 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/anyuliuxing/article/details/90369822