当前位置:网站首页>Qt原代码基本知识
Qt原代码基本知识
2022-07-02 10:26:00 【微光风笛】

untitled1.pro
#-------------------------------------------------
#
# Project created by QtCreator 2022-06-28T09:57:30
#
#-------------------------------------------------
# Qt应用到的模块
QT += core gui
# 兼容以前的Qt版本(一般不会更改)
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# 生成应用程序的名字
TARGET = untitled1
# 指生成的makfile类型
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# 源文件
SOURCES += \
main.cpp \
widget.cpp
# 头文件
HEADERS += \
widget.h
# UI文件
FORMS += \
widget.ui
# Qt应用到的模块QT += core gui# 兼容以前的Qt版本(一般不会更改)greaterThan(QT_MAJOR_VERSION, 4): QT += widgets# 生成应用程序的名字TARGET = untitled1# 指生成的makfile类型TEMPLATE = app
widget.h中
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
//定义UI的命名空间
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT //宏 如果使用信号和槽,必须添加此类
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui; //用UI命名空间里面的Widget类,定义一个指针*ui
};
#endif // WIDGET_H
Q_OBJECT //宏 如果使用信号和槽,必须添加此类
Ui::Widget *ui; //用UI命名空间里面的Widget类,定义一个指针*ui
widget.cpp中
#include "widget.h"
#include "ui_widget.h"
//构造函数
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
main.cpp
#include "widget.h" //因为主函数用了窗口,需要导入头文件
#include <QApplication>
int main(int argc, char *argv[])
{
//应用程序类,每个Qt应用程序中都有且只有一个应用程序对象
QApplication a(argc, argv);
//窗口类创建窗口对象,窗口创建出来默认不显示
Widget w; //顶层窗口
w.show(); //窗口显示
return a.exec(); //应用程序对象运行
}
exec()的作用是什么呢?
作用是开启一个循环,执行一个事件,相当于while(1)和for(;;)。保证窗口不是一闪即过
边栏推荐
- Android kotlin fragment technology point
- Explanation: here is your UFO, Goldbach conjecture
- Verification failed, please check your call back website. You can follow the instructions
- Code implementation MNLM
- SystemServer进程
- Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
- P1042 [NOIP2003 普及组] 乒乓球
- Everyone believes that the one-stop credit platform makes the credit scenario "useful"
- Browser driven Download
- Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
猜你喜欢

Simple introduction to ENSP

不会看器件手册的工程师不是个好厨子

Error function ERF

I did it with two lines of code. As a result, my sister had a more ingenious way

Bridge of undirected graph

Performance optimization of memory function

MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)

Unity skframework framework (XII), score scoring module

ensp简单入门

qt中uic的使用
随机推荐
Sum of the first n terms of Fibonacci (fast power of matrix)
BeanUtils--浅拷贝--实例/原理
【模板】最长公共子序列 (【DP or 贪心】板子)
题解:《压缩技术》(原版、续集版)
Subcontracting configuration of uniapp applet subpackages
错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
Will your sleep service dream of the extra bookinfo on the service network
A better database client management tool than Navicat
[cloud native database] what to do when encountering slow SQL (Part 1)?
In 2021, the global TCB adapter revenue was about $93 million, and it is expected to reach $315.5 million in 2028
Browser driven Download
selenium,元素操作以及浏览器操作方法
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
Simple introduction to ENSP
Solution: Compression Technology (original version and sequel version)
Download files and preview pictures
Explanation of 34 common terms on the Internet
大家信夫一站式信用平台让信用场景“用起来
你的 Sleep 服务会梦到服务网格外的 bookinfo 吗
The 29 year old programmer in Shanghai was sentenced to 10 months for "deleting the database and running away" on the day of his resignation!