刚开始学习C++,对很多东西都不了解,由于在Ubuntu上,所以很容易的认识了QT,就像在Windows上会很容易认识MFC一样。QT确实很强大,我决定把我的学习过程记录下来,以备日后参考。先写一下我的入门知识(内容来自wiki.ubuntu.org.cn ),"Hello ubuntu!"。第一个是简单的QT3程序:
首先建立一个目录qt3hello,然后在里面新建一个文件main.cpp,内容如下:
- <SPAN style="FONT-SIZE: x-small">#include <qapplication.h>
- #include <qpushbutton.h>
-
- int main( int argc, char **argv )
- {
- QApplication a( argc, argv);
-
- QPushButton hello("Hello ubuntu!", 0);
- hello.resize(100,30);
-
- a.setMainWidget( &hello);
- hello.show();
- return a.exec();
- }</SPAN>
#include <qapplication.h>
#include <qpushbutton.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv);
QPushButton hello("Hello ubuntu!", 0);
hello.resize(100,30);
a.setMainWidget( &hello);
hello.show();
return a.exec();
}
然后用以下命令编译运行
- <SPAN style="FONT-SIZE: x-small">$ cd ~/qt3hello
- $ qmake -project
- $ qmake
- $ make
- $ ./qt3hello</SPAN>
$ cd ~/qt3hello
$ qmake -project
$ qmake
$ make
$ ./qt3hello
这一个是QT4的例子,内容同样来自wiki.ubuntu.org.cn,但那上面的编译命令是错的,浪费了我这种初学者很多时间。我改正了一下。
首先建立文件夹qt4hello,在其中建立文件main.cpp,内容如下:
- <SPAN style="FONT-SIZE: x-small">#include <QApplication>
- #include <QPushButton>
-
- int main( int argc, char *argv[])
- {
- QApplication app(argc, argv);
-
- QPushButtion hello("Hello Ubuntu!");
- hello.resize(100,30);
-
- hello.show();
- return app.exec();
- }</SPAN>
#include <QApplication>
#include <QPushButton>
int main( int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButtion hello("Hello Ubuntu!");
hello.resize(100,30);
hello.show();
return app.exec();
}
使用以下命令编译
- <SPAN style="FONT-SIZE: x-small">$ cd ~/qt4hello
- $ qmake-qt4 -project
- $ qmake-qt4
- $ make
- </SPAN>
$ cd ~/qt4hello
$ qmake-qt4 -project
$ qmake-qt4
$ make
然后运行
- <SPAN style="FONT-SIZE: x-small">$ ./qt4hello</SPAN>
$ ./qt4hello
OK!
下面对QT程序的执行总结一下。以QT3为例,QT4也差不多。
头文件qapplication.h包含了类QApplaction的定义。所有QT程序都必需QApplication的一个对象。QApplication管理着程序的很多资源,能够实时监测系统状态对程序作出反馈。
头文件qpushbutton.h包含QPushButton类的定义。
首先生成一个QApplication对象,然后用a.setMainWidget(&hello)将QPushButton对象作为这个应用程序的主窗口部件。
a.exec();是将控制交给QT的时候,当程序执行完时,exec()会返回。
到这已经大体明白了QT的最基本的东西。我相信自己会把它给搞定的。
转载于wolfplanet。iteye.com
相关推荐
1. 使用QT开发的简易串口程序 2. 使用socat 虚拟串口,可在linux系统下测试。
ubuntu20.04安装QT 一、 安装cmake 二、 安装gcc和g++ 三、 下载QT 四、 安装QT 五、 故障解决
安装qt5.12.1中的mqtt的库,首先要先安装qt5.12.1,保证qmake 能用在运行脚本
简单介绍如何在Ubuntu下进行Qt的静态编译,并用编译出来的静态库编译我们的程序
ubuntu下QT安装方法 ubuntu下QT安装方法 ubuntu下QT安装方法 ubuntu下QT安装方法
在ubuntu下qt读取excel文件,该文件只支持xls格式,在使用过程中遇到的坑与大家分享一下
ubuntu下基于Clion+QT编写的界面demo,适合入门, 博客请参考:https://yongqi.blog.csdn.net/article/details/125698957
写了点Qt界面程序,然而发现很难移植到其他没有安装Qt环境的电脑上运行。查资料了解到,在windows上有windowsdeployqt程序,linux上有linuxdeployqt可以帮助我们快速打包。 1. 配置Qt环境 首先,我们先把Qt环境配置...
ubuntu 20.04 安装QT
详细讲述Ubuntu 建立 QT4开发环境
本文档主要讲解ubuntu下QT连接数据库的时出现的各种驱动加载错误的问题的解决方法
Ubuntu下操作Excel,实现合并单元格,设置单元格背景色,添加边框,设置字体,等一系列功能。需要安装xlslib库
QT linux
Ubuntu下QT显示中文乱码问题.docx
ubuntu下QT调用百度地图的HTML文件,在界面显示地图,可以输入经纬度进行定位
Ubuntu下Yocto搭建QT编译环境源文件
ubuntu16.04 下在qt 5.9.0 下采用opengl 利用glut画3维坐标系
ubuntu下安装QT依赖 sudo apt-get install libqt3-dev不行
linux/麒麟/ubuntu 下qt4.8.7安装包
QT5.12.2/QT5.12.5 QWebEngineView Ubuntu下编译版本 支持MP3MP4播放,直接解压就可以用。