当前位置:网站首页>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(;;)。保证窗口不是一闪即过
边栏推荐
- P1908 逆序对
- [template] longest common subsequence ([DP or greedy] board)
- Don't spend money, spend an hour to build your own blog website
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
- BeanUtils -- shallow copy -- example / principle
- Qt如何设置固定大小
- JS reverse row query data decryption
- 三谈exception——错误处理
- Android kotlin fragment technology point
- ensp简单入门
猜你喜欢

Runhe hi3516 development board openharmony small system and standard system burning

题解《子数整数》、《欢乐地跳》、《开灯》

When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview

QT new project_ MyNotepad++

SystemServer进程

Selenium, element operation and browser operation methods

Qt-制作一个简单的计算器-实现四则运算

无主灯设计:如何让智能照明更加「智能」?

selenium,元素操作以及浏览器操作方法

In 2021, the global styrene butadiene styrene (SBS) revenue was about $3722.7 million, and it is expected to reach $5679.6 million in 2028
随机推荐
ensp简单入门
Qt-制作一个简单的计算器-实现四则运算-将结果以对话框的形式弹出来
科技的成就(二十七)
Dingtalk 发送消息
Chinese name extraction (toy code - accurate head is too small, right to play)
QT - make a simple calculator - realize four operations
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology
693. Travel sequencing (map + topology)
[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
D如何检查null
Partner cloud form strong upgrade! Pro version, more extraordinary!
故事點 vs. 人天
selenium的特点
Pattern matching and regular expressions in PostgreSQL - Das
The xftp connection Haikang camera reported an error: the SFTP subsystem application has been rejected. Please ensure that the SFTP subsystem settings of the SSH connection are valid
Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
Browser driven Download
为什么switch 的default后面要跟break?
On flow delivery between microservices
D how to check null