其实就是和Qt::QueuedConnection时的信号槽一样,属于异步的。

1、新建QEvent子类

①、头文件

#ifndef MYEVENT_H

#define MYEVENT_H

#include <QString>

#include <QEvent>

class MyEvent : public QEvent

{

QString m_data;

public:

const static Type TYPE = static_cast<Type>(QEvent::User + 0xFF);

MyEvent(QString data = "");

QString data();

};

#endif // MYEVENT_H

②、cpp

#include "myevent.h"

MyEvent::MyEvent(QString data) : QEvent(TYPE)

{

m_data = data;

}

QString MyEvent::data()

{

return m_data;

}

2、在任何需要发送消息的地方

QApplication::postEvent(parent(), new MyEvent("Begin"));//必须在堆上建空间

for(int i=0; i<10000; i++)

{

QApplication::postEvent(parent(), new MyEvent(QString::number(i)));

msleep(1);

}

QApplication::postEvent(parent(), new MyEvent("End"));

3、在主界面中处理消息

bool MainWindow::event(QEvent *evt)

{

bool ret = true;

if( evt->type() == MyEvent::TYPE )

{

MyEvent* se = dynamic_cast<MyEvent*>(evt);

if( se != NULL )

{

ui->plainTextEdit->appendPlainText(se->data());

}

}

else

{

ret = QWidget::event(evt);

}

return ret;

}

异步消息postEvent更新界面的更多相关文章

  1. Android Service 通知Activity更新界面的方法研究

    Android Service 通知Activity更新界面的方法研究   Android的最重要的组件式service和activity,那么在使用的过程中,我们最常遇到的问题是他们之间的通信问题. ...

  2. Android:Service通知Activity更新界面

    Android有四大组件,其中包括service和activity,那么在使用的过程中,我们最常遇到的问题是他们之间的通信问题. 1.首先Activity调用Service 这个是比较基础的,它有两种 ...

  3. windows程序消息机制(Winform界面更新有关)

    windows程序消息机制(Winform界面更新有关) 转自:http://www.cnblogs.com/blosaa/archive/2013/05/31/3109586.html 1. Win ...

  4. Android 异步加载数据 AsyncTask异步更新界面

    官方文档:     AsyncTask enables proper and easy use of the UI thread. This class allows to perform backg ...

  5. #研发中间件介绍#异步消息可靠推送Notify

    郑昀 基于朱传志的设计文档 最后更新于2014/11/11 关键词:异步消息.订阅者集群.可伸缩.Push模式.Pull模式 本文档适用人员:研发   电商系统为什么需要 NotifyServer? ...

  6. Android--Handler的用法:在子线程中更新界面

    本文主要介绍Android的Handler的用法.Handler能够发送Messsage和Runnable对象到与其相关联的线程的消息队列. 每一个Handler对象与创建它的线程相关联.而且每一个H ...

  7. Bitter.NotifyOpenPaltform : HTTP 异步消息接收调度中心&mdash;开源贡献 之 一:简介

    现在互联网的系统越来越趋向于复杂,从单体系统到现在的微服务体系演变.公司与公司的分工也越来越明确. 大数据公司提供了大数据服务 人脸识别公司提供了人脸识别服务 OCR 公司提供了专业的OCR 服务 车 ...

  8. Bitter.NotifyOpenPaltform : HTTP 异步消息接收调度中心--开源贡献 之 一:简介

    现在互联网的系统越来越趋向于复杂,从单体系统到现在的微服务体系演变.公司与公司的分工也越来越明确. 大数据公司提供了大数据服务 人脸识别公司提供了人脸识别服务 OCR 公司提供了专业的OCR 服务 车 ...

  9. 扩展BindingList,防止增加、删除项时自动更新界面而不出现“跨线程操作界面控件 corss thread operation”异常

    在做界面程序时,常常需要一些数据类,界面元素通过绑定等方式显示出数据,然而由于UI线程不是线程安全的,一般都需要通过Invoke等方式来调用界面控件.但对于数据绑定bindingList而言,没法响应 ...

随机推荐

  1. Cocos2d-x 3.3Bate0 ExpandedListView

    之前写的ExpandedListView版本号因为版本号升级这里提供Cocos2d-x 3.3Bate0 版本号 代码下载:http://download.csdn.net/detail/qqmcy/ ...

  2. UITabBarItem如何更改高度

    本文转载至 http://www.cocoachina.com/bbs/read.php?tid=255361 我目前有个UITabBar,改了它的高度.但是我切换页签后,这个UITabBar样式又变 ...

  3. MVC结构简介

    本文编译自J2EE的相关文档.MVC(Model-View-Controller)应用程序结构被用来分析分布式应用程序的特征.这种抽象结构能有助于将应用程序分割成若干逻辑部件,使程序设计变得更加容易. ...

  4. dubbo zookeeper报错failed to connect to server , error message is:No route to host

    failed to connect to server , error message is:No route to host 转自:http://blog.csdn.net/miaohongyu1/ ...

  5. ZOJ 3331 Process the Tasks(双塔DP)

    Process the Tasks Time Limit: 1 Second      Memory Limit: 32768 KB There are two machines A and B. T ...

  6. 找不到Microsoft Access Driver(*.mdb)ODBC驱动程序的安装例程。请重新安装驱动

    按照教材创建的方法:“控制面板-管理工具-数据源(ODBC)”,打开“ODBC数据源管理器”窗口,然后“添加”,打开“创建新数据源”的窗口,最后选择Microsoft Access Driver(*. ...

  7. windows python easy_install ,pip. selenium

    http://www.cnblogs.com/fnng/p/3157639.html 搭建平台windows 准备工具如下: unknown encoding: cp65001异常 python安装后 ...

  8. office 2013 activiate---(run as admin)

    win7 office 2013 activiate---(run as admin) empty the garbage in osx rm -rf ~/.Trash

  9. python中open函数的使用

    转自:https://www.cnblogs.com/R-ling/p/8412578.html 一.open()的函数原型open(file, mode=‘r', buffering=-1, enc ...

  10. SSH 框架整合总结

    1. 搭建Struts2 环境 创建 struts2 的配置文件: struts.xml; 在 web.xml 中配置 struts2 的核心过滤器; // struts.xml <?xml v ...