第一个Qt程序
来源:互联网 发布:平湖市行知小学黄老师 编辑:程序博客网 时间:2024/04/29 22:30
一、Qt的安装
使用的Linux系统Ubuntu14.10是已经安装好QT的
查看Qt版本,执行
qmake -vQt
可以看到版本为:version 4.8.6
若没有的话,自己安装一个也不难,相关教程网上都有,这里就不多说了。
二、开始编写第一个Qt程序:hello world
1、编写源文件:hello.cpp
#include <qapplication.h>
#include <qlabel.h>
int main(int argc, char **argv)
{
QApplication a(argc, argv); //create a window
QLabel hello("Hello world!", 0); //create a label
hello.resize(150, 50); //set size of label: width 150,high 50
//a.setMainWidget(&hello); //
hello.show(); //show the label
return a.exec(); //draw the form
}
2、建立工程文件:hello.pro
SOURCES = hello.cpp
HEADERS =
CONFIG += qt warn_on release
3、编译和运行程序
(1)预处理工程,生成makefile文件:
qmake -o makefile hello.pro
(2)编译程序:
make
(3)运行程序:
./hello
三、注意
源文件中注释了一行代码,不注释会发现提示错误:
“setMainWidget”: 不是“QApplication”的成员
这是由于setMainWidget是QT3的,QT4以后就不用了,没必要再setmainwidget了,直接删掉,并show出你的窗口就行了
使用的Linux系统Ubuntu14.10是已经安装好QT的
查看Qt版本,执行
qmake -vQt
可以看到版本为:version 4.8.6
若没有的话,自己安装一个也不难,相关教程网上都有,这里就不多说了。
二、开始编写第一个Qt程序:hello world
1、编写源文件:hello.cpp
#include <qapplication.h>
#include <qlabel.h>
int main(int argc, char **argv)
{
QApplication a(argc, argv); //create a window
QLabel hello("Hello world!", 0); //create a label
hello.resize(150, 50); //set size of label: width 150,high 50
//a.setMainWidget(&hello); //
hello.show(); //show the label
return a.exec(); //draw the form
}
2、建立工程文件:hello.pro
SOURCES = hello.cpp
HEADERS =
CONFIG += qt warn_on release
3、编译和运行程序
(1)预处理工程,生成makefile文件:
qmake -o makefile hello.pro
(2)编译程序:
make
(3)运行程序:
./hello
三、注意
源文件中注释了一行代码,不注释会发现提示错误:
“setMainWidget”: 不是“QApplication”的成员
这是由于setMainWidget是QT3的,QT4以后就不用了,没必要再setmainwidget了,直接删掉,并show出你的窗口就行了
0 0
- 第一个Qt程序
- 第一个QT程序
- 第一个Qt程序
- 第一个Qt程序
- 第一个qt程序
- 第一个QT程序
- [QT]第一个QT程序
- 开始第一个Qt程序
- 第一个QT对话框程序
- 第一个Qt程序 Helloworld
- Qt第一个程序详解
- 170318 Qt-第一个程序
- Qt第一个程序 HelloWorld
- 2.第一个QT程序
- Qt:运行第一个Qt程序
- QT——第一个QT程序
- QT第一个程序 hello,world
- 第一个qt程序:hello world!
- Grub 的修复过程
- ajax跨域问题。
- Java-----String对象的经典问题(new String())
- 探究Java File类中list()、listFiles()的使用及区别,认识和使用匿名内部类
- 学习笔记——定位基础
- 第一个Qt程序
- 体系结构之设计基础
- Build Qt 5.4 in windows: use VS2010
- linux用户与用户组
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- postgresql 创建数据库提示错误
- iOS 每天提醒和每周提醒
- 【C语言】编写一个函数,将一个数字字符串转换成该字符串对应的数字(包括正整数、负整数)。
- hdu1754 I Hate It(线段树)