本文用于记载在Linux上安装QT及在此过程中遇到的各种问题,百度中有很多版本的解决方法,可是太多都模棱两可,方法也千篇一律,不能实际解决问题,本文仅用于打卡,为以后的此类问题找到一个可追溯的文档。
一, 软件说明
本人使用的虚拟机是VMware-workstation-full-14.1.1.28517.exe
Linux版本是ubuntukylin-16.04-desktop-amd64.iso
QT版本是qt-opensource-linux-x64-5.8.0.run
二,环境配置
QT环境配置(qmake):
在网上有很多QT配置的网页,我在试用了很多次之后,终于配置成功
vim /etc/profile 在/etc/profile文档中的最下面加入以下数据
export PATH=/home/wwb/Qt5.8.0/5.8/gcc_64/bin:$PATH
export QTDIR=
/home/wwb/Qt5.8.0/5.8/gcc_64
export MANPATH=$QTDIR/man:$MANPATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
其中
/home/wwb/Qt5.8.0/5.8/gcc_64是QT的安装绝对路径,
查看qt的安装路径命令:locate qt | grep bin
qt环境配置好检验方法:qmake -v 如果显示位置,则表示配置成功
如果不想到qtcreator目录下运行./qtcreator文件才能打开qtcreator的话,直接在终端输入qtcreator命令就能打开qtcreator 就还得配置
vim /etc/profile 在/etc/profile文档中的最下面加入以下数据
export PATH=/home/wwb/Qt5.8.0/Tools/Qtcreator/bin:$PATH
export QTDIR=
/home/wwb/Qt5.8.0/Tools/Qtcreator
export MANPATH=$QTDIR/man:$MANPATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
其中 /home/wwb/Qt5.8.0/Tools/Qtcreator为Qtcreator的路径
三,QT常见错误
错误1:error while building/deploying project HelloQT
解决方法:新建工程文件中或者路径中存在了中文字符,把中文字符改成英文。程序中最好都使用英文,中文会出现各种各样 的问题
错误2:QApplication:No such file or directory
解决方法:本问题是出现在生成了.Pro文件后,在执行 qmake hello.pro 后出现的问题,
找不到QApplication定义
在产生的的.pro 文件中加入一个头文件就可解决
vim hello.pro
加入 QT +=widgets
错误3:cannot find -lGL
collect2: 1d returned 1 exit status
解决方法:本错误出现在执行make命令后,没有生成 .o 文件和可执行文件,这是因为系统缺少链接库,执行两条命令即可解决
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglu1-mesa-dev freeglut3-dev
错误4:E:Encountered a section with no Package: header
解决方法:本错误出现在解决错误3时出现的,执行
sudo apt-get install libgl1-mesa-dev时显示以上错误
输入 sudo apt-get update 命令即可解决
四,简单的helloqt程序
#include<QApplication>
#include<QLabel>
int main (int argc,char *argv[])
{
QApplication hello(argc,argv);
QLabel *label = new QLabel("Hello,Qt");
label->show();
return hello.exec();
}
{
QApplication hello(argc,argv);
QLabel *label = new QLabel("Hello,Qt");
label->show();
return hello.exec();
}
命令编译:qmake -project #生成.pro项目文件
qmake hello.pro # 生成Makefile文件
make # 生成.o目标文件和可执行文件
./hello # 执行可执行文件hello