当前位置:网站首页>Qt学习第一天
Qt学习第一天
2022-07-28 15:22:00 【tyrocjl】
(一)Qt相关
可以在bash直接执行
1)assistant(Qt助手)//Qt帮助手册
2)qmake(Qt构建器)
3)designer(Qt设计师)//图形化编辑工具
4)uic(Qt界面转换器)//将ui文件抓换为c++代码
5)moc(Qt元对象编译器)//将qt语法扩展还原为标准C++
6)rcc(Qt资源编译器)//将图片等资源编译为C++代码
7)qtcreator(Qt创造器)//Qt的继承开发环境(IDE)Qt帮助手册使用(assistant)
1)先读第一句话,了解该类类功能,如果看不懂,可以“more”链接,跳转详细说明位置.
2)往下了解头文件、构建选项(QT+=widgets)、继承关系
3)Properties(成员变量)
4)Public Functions(公有的成员函数)
5)Reimplemented Public Functions(重实现的公有虚函数)
6)Public Slots(槽函数)//Qt语法扩展
7)Signals(信号)//Qt语法扩展
8)Static Public Members(静态的公有成员)
9)Reimplemented Protected Functions(保护的虚函数)
10)Detailed Description(详细说明)
(二)第一个程序
- 创建工程目录
mkdir Hello
注:每个Qt程序都应该放在独立目录下 - 进入工程目录,编写源代码(cpp)
cd Hello
vi main.cpp - 执行“qmake -project”,生成与平台无关的工程文件(Hello.pro)
注:需要向工程添加qmake构建选项
QT += widgets //将来加载widgets模块对应头文件和库文件 - 执行“qmake”,根据上一步工程文件,生成编译链接的Makefile
- 执行“make”,根据Makefile完成编译和链接
- 测试运行“./Hello”
注:如果代码有语法错误,修改代码后,再次执行"make"即可,前面3、4无需重复执行.#include <QApplication> #include <QLabel> int main(int argc,char** argv){ //创建Qt应用程序 QApplication app(argc,argv); //创建标签控件(组件\部件\构件) QLabel label("Hello Qt!"); //显示标签 label.show(); //让应用程序进入事件循环 return app.exec(); }
(三)Qt字符串
常见编码
1)linux系统默认:utf-8
2)windows系统默认:gbk/gb2312/gb18030
3)Qt的QSring字符串默认:unicode(utf-16)编码转换类(QTextCodec)
//创建GBK编码对象
QTextCodec *codec = QTextCodec::codecForName(“GBK”);
//将GBK中文字符串转换为unicode编码
QString string = codec->toUnicode(“GBK中文字符串”);
注:如果构造QString字符串对象时,如果没有显式转码,用的是utf-8的"常量字符串"默认会调用fromUtf8将其自动转换为Qt内部使用unicode编码. 当然,如果不是utf-8的字符串,同样会默认调用fromUtf8,只不过会乱码罢了。
(四) 父窗口(容器窗口)
父窗口可以用于管理整个界面,在创建控件时可以指定停靠在父窗口上面,如果没有指定父窗口则飘在外面形成独立的窗体.
常用的父窗口类
1)QWidget //图形控件基类
2)QMainWindow //主窗口(QWidget子类)
3)QDialog //对话框(QWidget子类)QWidget类中两个常用成员函数
1)调整父窗口或控件大小
void resize(int w,int h);
2)调整父窗口或控件位置
void move(int x,int y);#include <QApplication> #include <QLabel> #include <QPushButton> #include <QWidget> #include <QDialog> #include <QMainWindow> #include <QFont>//字体 int main(int argc,char** argv){ QApplication app(argc,argv); //创建父窗口对象 //QWidget parent; //QDialog parent; QMainWindow parent; //设置父窗口字体大小 QFont font; font.setPointSize(20); parent.setFont(font); //设置父窗口大小和位置 parent.resize(480,320); parent.move(200,100); //创建label并停靠在父窗口上面 QLabel label("我是标签",&parent); label.move(50,50); label.resize(150,50); //创建button并停靠在父窗口上面 QPushButton button("我是按钮",&parent); button.move(50,200); button.resize(150,50); //动态创建button并停靠在父窗口上面 //当父窗口被销毁时,上面停靠的动态对象会自动被 //delete,无需手动执行detele. QPushButton* button2 = new QPushButton("我也是按钮",&parent); button2->move(300,200); button2->resize(150,50); //显示父窗口,上面停靠的控件也会一起被显示 parent.show(); return app.exec(); }
边栏推荐
- Basic structure and operation principle of solar street lamp
- LwIP development | realize TCP server through socket
- 小程序中的分页查询
- 百度编辑器ueditor,编辑内容过多时,工具栏不可见,不方便编辑或上传问题
- Remember the common JS methods of projects
- Roson的Qt之旅#102 ListModel
- 2021 肯特面试题3
- JS priority queue
- I came across Digital Phoenix coordinate Xuhui Meiluo city in Shanghai
- ffmpeg获取首帧
猜你喜欢

正大杯黑客马拉松数据解析竞赛

JS bidirectional linked list 01

深入理解Istio流量管理的熔断配置

Two special functions (arrow function and method)

JS linked list 02

Stm32cube infrared remote control: input capture

flashfxp 530 User cannot log in. ftp

Ask if you don't understand, and quickly become an advanced player of container service!

High speed counter to rs485modbus RTU module ibf150

2021 亚鸿笔试题
随机推荐
小程序中的分页查询
LabVIEW Linx toolkit controls Arduino equipment (expansion-1)
Instructions for mictr01 Tester development kit (vibrating wire acquisition reader)
curl无输出返回空白或者null问题解决
I came across Digital Phoenix coordinate Xuhui Meiluo city in Shanghai
Application of optical rain gauge to rainfall detection
两种特殊函数(箭头函数和方法)
李宏毅《机器学习》丨5. Tips for neural network design(神经网络设计技巧)
SDL2 简明教程(四):用 SDL_IMAGE 库导入图片
Notes on October 22, 2021
Numpy ndarray learning < II > miscellaneous records
动态规划 --- 数位统计DP
兆骑科创创新创业大赛人才引进平台,双创赛事高层次人才引进
2-channel Di high-speed pulse counter, 1-channel encoder to Modbus TCP wired wireless module ibf161
Detailed explanation of QT qstring
JS linked list 02
食品安全 | 这两类瓜果宜改善便秘 孕妇人群尤其建议
Huada chip hc32f4a0 realizes RS485 communication DMA transceiver
[Multisim Simulation] LM339 zero crossing circuit simulation
解决电脑恶意广告弹窗的思路