一、安装qt5
确定系统能正常上网后,终端中运行下面命令(大约要650M空间,用超级用户安装。)。
sudo apt-get install qt5-default qt5-qmake g++ qtcreator
运行结果:
……
下列软件包将被升级:
libqt5concurrent5 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5opengl5 libqt5printsupport5 libqt5sql5 libqt5test5 libqt5widgets5
libqt5xml5
升级了 11 个软件包,新安装了 93 个软件包,要卸载 0 个软件包,有 95 个软件包未被升级。
需要下载 222 MB 的归档。
解压缩后会消耗 649 MB 的额外空间。
……
qtcreator 新版本安装:
从深度应用商店 中查找qt-sdk
查找到qtcreator ,安装。
二、启动QT5
1.从深度应用商店启动
从安装的 深度应用商店 运行qtcreator, 把他定在任务栏 上。
运行时后
空间不够 /home/mabao/.config/QtProject/qtcreator/ 下面不能建立文件了。
mkdir /home/mabao/.config/QtProject/
mkdir /home/mabao/.config/QtProject/qtcreator/
qtcreator还是不能建立文件,权限不够。
打开终端,进入超级用户 sudo su
直接运行qtcreator
#qtcreator
没有告警了。
这是从超级用户命令行启动。
2.从深度linux 启动器快捷方式启动
深度linux 启动器快捷方式列表中显示qtcreator 快捷的问题。
qtcreator 安装后,在深度 启动器快捷方式列表中看不到其快捷方式。
cd /usr/share/applications/
ls 显示却看到 org.qt-project.qtcreator.desktop 有
查看org.qt-project.qtcreator.desktop
sudo gedit /usr/share/applications/org.qt-project.qtcreator.desktop
[Desktop Entry]
Type=Application
Exec=qtcreator %F
Name=Qt Creator
GenericName=C++ IDE for developing Qt applications
X-KDE-StartupNotify=true
Icon=QtProject-qtcreator
Terminal=false
Categories=Development;IDE;Qt;
MimeType= text/x-c++src;text/x-c++hdr;text/x-xsrc;application/x-designer;application/vnd.qt.qmakeprofile;application/vnd.qt.xml.resource;
查看快捷方式也没有问题。
难道是名字问题,名字太长?拷贝一个备份
cp org.qt-project.qtcreator.desktop qtcreator.desktop
再查看 启动器快捷方式列表 有了。哈哈!
修改为以管理员身份运行,修改Exec 项,增加gksu(注意不是sudo)
sudo gedit /usr/share/applications/qtcreator.desktop
Exec=gksu qtcreator %F
保存。用这个快捷就可以用超级用户(管理员身份)qt5.
后来发现,重启系统后,org.qt-project.qtcreator.desktop 也是可以显示在启动器里面的。
不过没有超级用户权限。
三、qtcreator 建立第一个新工程
在弹出的界面中选择”其它项目“——”empty qmake project"——“choose"
建立的新工程名helloworld,没有kit
添加 kit ,找不到qt 版本,手中找qmake 没有有关的应用程序。
g++,gcc 是在/usr/bin 里面的
linux 通过ln -s建立链接文件后,如何通过链接文件查看源文件
ls -l
mabao@mabao-PC:~/Desktop$ cd /usr/bin
mabao@mabao-PC:/usr/bin$ ls qmake
qmake
mabao@mabao-PC:/usr/bin$ ls -l qmake
lrwxrwxrwx 1 root root 9 4月 21 00:18 qmake -> qtchooser
原来 qtcreator 还需要qt5-qmake
还是要通过 sudo apt-get install qt5-default qt5-qmake g++ qtcreator 来安装。
可以找到qmake在 /usr/lib/x86_x64-linux-gnu/qt5/qmake
可以添加 kit 了。
重启qtcreator,它自己也找到qt5 版本了。
编写一个main.cpp 程序,添加到工程helloworld
#include<QApplication>
#include<QLabel>
int main(int argc, char** argv)
{
QApplication app(argc,argv);
QLabel *label = new QLabel("Hello world!");
label->show();
return app.exec();
}
构建(编译)工程helloworld:
QApplication 没找到
选择-qbs 里面看到profiles页下面 列表树 qt-core 有incPath 指向/usr/include/x86_x64-linux-gnu/qt5/
文件管理器中找 QApplication 在目录
/usr/include/x86_x64-linux-gnu/qt5/QtWidgets
修改include 如下:
#include<QtWidgets/QApplication>
#include<QtWidgets/QLabel>
再构建,出错
QApplication::QApplication(int&, char**, int)’未定义的引用....
修改 helloword.pro 文件,在最后添加两行如下:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
保存
再构建成功,运行成功。qt5已经安装正常可用。