Qt基础之七:事件循环

目录

一.一个最简单的Window API窗口程序

二.事件循环

三.QEventLoop

1.延时

2.局部对话框的显示

3.同步获取数据


一.一个最简单的Window API窗口程序

Qt在Windows上的实现实际上就是对Window API的封装,我们先创建一个最简单的窗口程序,方便查看Window API调用流程。

#include <windows.h>
// 声明窗口过程函数
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    // 注册窗口类
    WNDCLASS wc = { 0 };
    wc.style = CS_HREDRAW | CS_VREDRAW; // 窗口样式
    wc.lpszMenuName = NULL; // 窗口菜单
    wc.lpfnWndProc = WindowProc; // 窗口处理函数
    wc.hInstance = hInstance;
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpszClassName = L"MyWindowClass";

    if (!RegisterClass(&w
QT_QEventLoop类的使用 QEventLoop是Qt中的事件循环类,它提供了一种进入和离开事件循环的方法。事件循环是一种机制,用于接收、分发和处理来自窗口系统、网络、定时器等的事件。QEventLoop可以启动一个本地的事件循环,用于处理特定的事件,例如等待网络响应或模态对话框。 阅读详情

相关推荐

Qt开发:事件循环

本文主要介绍Qt中事件循环的工作原理和方法。

TechNomad的博客 2251

QT消息/事件循环机制

关于Qt子线程和消息循环 一、QT消息/事件循环机制 Qt作为一个可视化GUI界面操作系统,是基于事件驱动的,我们程序执行的顺序不再是线性,而是由一个个应用程序内部或外部的事件进行驱动,无事件时便阻塞。这个循环概念类似于while的函数循环,函数体内不断处理用户的输入,类比到事件循环中,用户点击了鼠标、按下了键盘,便被称作为事件。 一般对于带UI窗口的程序来说,“事件”是由操作系统或程序框架在不同的时刻发出的。当用户按下鼠标、敲下键盘,或者是窗口需要重新绘制的时候,计时器触发的时候,都会发出一个相应的事件。

weixin_43772452的博客 3363

Qt:事件和事件循环

最近想要了解一下Qt线程,但在对相关资料师都是从线程和事件循环开始将。对于事件循环是个相对很抽象的概念,研究了很久也很难在脑子里建立起一个具体的模型。今天在这里对这几天研究内容做总结,为以后做参考。      先说事件,网上很多资料都将的很清楚。在这里重点是明确一下一个事件发出后对于该事件的一个调用顺序。在这里我们在QApplication安装一个过滤器,在一个一个Qwidget安装一个过滤器

cfqcfqcfqcfqcfq的博客 7300

Qt事件循环调用过程

Qt事件循环调用代码,事件循环

weixin_45415069的博客 1417

Qt 事件循环

一、QT消息/事件循环机制   Qt作为一个可视化GUI界面操作系统,是基于事件驱动的,我们程序执行的顺序不再是线性的,而是由一个个应用程序内部或外部的事件进行驱动的,无事件时便阻塞。这个有点类似于while循环,函数体内不断处理用户的输入,类比到事件循环中,用户点击了鼠标,按下了键盘,便称为事件。   一般对于带UI窗口的程序来说,“事件”是由操作系统或程序框架在不同的时刻发出的。当用户按下鼠标,敲下键盘,或是窗口需要重新绘制的时候,或是计时器触发的时候,都会发出一个相应的事件。下面是一个抽象的“循环事件

QtCompany的博客 1085

QT应用编程: 使用QEventLoop实现事件循环

一、环境介绍 操作系统:win10 64位 QT版本:QT5.12.6 二、QEventLoop类 QEventLoop类提供了一种进入和离开事件循环的方法。 在任何时候,你都可以创建一个QEventLoop对象并对其调用exec(),以启动本地事件循环,在事件循环中,调用exit()将强制exec()返回。另请参见QAbstractEventDispatcher。 QEventLoop 常规运用环境 : 在主界面里执行某个代码之前,需要等待某个条件成立,但是这个条件是其他线程...

2466

ANPC三电平拓扑:两种调制方式解析

ANPC结构是基于“I”型NPC结构(下面讲NPC如不特殊说明,均指的是“I”型结构NPC)发展出来的一种改进型。我们在讲NPC结构的时候会谈到他的一个缺点就是损耗分布不均匀,会导致温升不均衡,进而限制模块的功率输出能力。而ANPC结构由于多了两个开关管以及相应的两个中性点换流回路(如下图),可以更加灵活任意的配置开关管可以使损耗没有那么的不均衡,从而能一定程度上提高模块的输出功率。ANPC拓扑结构图以及增加的环流回路。

IOTBOT的博客 9606

Figma入门-自动布局

Figma原型图制作内置组件友好,自动布局类似CSS flex,通过布局网格控制对齐、分布、换行等,前端熟悉的同学易上手,参数设置基本一致。

我码玄黄的博客 2179

ABAP内表数据导出Excel:OLE、ALV与GUI_DOWNLOAD方案全解析

在企业级应用开发中,数据导出是连接后台系统与前端业务分析的关键桥梁。其核心原理是将结构化数据转换为通用文件格式,以实现跨平台的数据交换与可视化。从技术价值看,一个健壮的导出功能能显著提升数据处理效率,减少人工干预,是衡量系统实用性的重要指标。常见的应用场景包括报表生成、数据交接和临时数据提取。本文聚焦于SAP ABAP开发领域,深入探讨如何将内表数据高效、稳定地导出至Excel,涵盖了OLE自动化、ALV标准导出以及基于CL_GUI_FRONTEND_SERVICES与GUI_DOWNLOAD的通用方案,并

weixin_32715349的博客 332

个人整理的数据集(手写中文数据、发票数据、快递单数据、车牌数据)

本人在工作生活中收集了各个方面比较多的真实的数据集如下: 一、手写中文数据集 1、档案类数据: 此数据集为手写档案数据,数量较大,大约128G,图像均未标注。 ex: 2、手写作文数据: 此数据集为手写作文数据,是大约800M左右,图像按行提供位置和内容标注,十分珍贵。 ex: 二、发票数据集: 1、增值税发票 此数据集包含了大量真实的增值税发票数据,大约9G,标注了发票位置数据,未提供详细标注。 ex: 2、购车发票 此数据集未提供标注。

weixin_43143224的博客 5906

VM下安装linux虚拟机(ubuntu)和Intel parallel XE 2013(ifort2013)

VM下安装ubuntu和ifort2013跑自己的模式 由于新冠疫情,本人只能在家工作,很多重要的文件和程序都留在了办公室的linux机器上,工作无法正常开展。本来准备去办公室把机器搬回家不曾想学校所有门禁都关闭,不许进入,何时解禁也没有明确日期。科研不能等人,没条件科研只能想办法创造条件了。 以前在自己的笔记本(windows)上装过一次VM和ifort但无奈程序不能正常跑,所以之前就放弃了。本...

pangdahai3366的博客 1501

别再死记硬背MAML原理了!用PyTorch手撸一个Omniglot小样本分类器(附完整代码)

本文详细介绍了如何使用PyTorch实现MAML(模型无关的元学习)算法,构建一个Omniglot小样本分类器。通过实战代码演示,帮助读者理解MAML的双层优化原理,并提供了完整的训练循环、网络架构设计及调试技巧,适合想要掌握元学习技术的开发者。

weixin_29191669的博客 136

vLLM 显存泄漏与 OOM 深度排查:从日志到火焰图

系统性地排查 vLLM 运行中的显存泄漏和 OOM 问题,包括 CUDA 内存快照、PyTorch 内存分析器、火焰图工具。

kaixin110a的博客 201

YOLOv8 超参数调优教程! 使用Ray Tune进行高效的超参数调优!

YOLOv8超参数调优教程!😎 使用Ray Tune进行高效的超参数调优!

Coding... 1万+

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Qt基础之十二:Qt多线程基础
下一篇: Qt基础之二十二:重启应用程序
草上爬
草上爬 领域专家: C/C++技术领域 领域专家: C/C++技术领域
博客等级 码龄18年 1万+粉丝 661原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

草上爬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值