Qt事件和信号/插槽 [英] Qt Events and Signal/Slots

查看:301
本文介绍了Qt事件和信号/插槽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Qt世界中,事件和信号/槽的区别是什么?

In the Qt world what is the difference of events and signal/slots?

是否替换另一个?是事件是信号/槽的抽象?

Does one replace the other? Are events an abstraction of signal/slots?

推荐答案

Qt文档可能最好解释它


从抽象的QEvent类派生

代表在应用程序中发生
的事情或作为
应用程序需要知道的外部活动的
结果关于。
事件可以通过
接收和处理QObject子类的任何实例
,但它们特别与
小部件相关。该文档描述了如何在
典型应用程序中传递和处理
事件。

In Qt, events are objects, derived from the abstract QEvent class, that represent things that have happened either within an application or as a result of outside activity that the application needs to know about. Events can be received and handled by any instance of a QObject subclass, but they are especially relevant to widgets. This document describes how events are delivered and handled in a typical application.

slot是两个并行机制来完成相同的事情,一般来说,事件将由外部实体(例如Keyboard,Mouswheel)生成,并且将通过QApplication中的事件循环传递。一般来说,除非你设置代码,否则不会生成事件。您可以通过 QObject :: installEventFilter()过滤它们,或通过覆盖相应的函数来处理子类对象中的事件。

So events and signal/slots are two parallel mechanisms accomplishing the same things, in general an event will be generated by an outside entity (e.g. Keyboard, Mouswheel) and will be delivered through the event loop in QApplication. In general unless you set up the code you will not be generating events. You might filter them through QObject::installEventFilter() or handle events in subclassed object by overriding the appropriate functions.

信号和插槽更容易生成和接收,你可以连接任何两个QObject子类。它们通过元类处理(有一个看看你的moc_classname.cpp文件更多),但大多数你将产生的类间通信可能会使用信号和槽。信号可以立即传递或通过队列延迟(如果你使用线程)
可以产生一个信号

Signals and Slots are much easier to generate and receive and you can connect any two QObject subclasses. They are handled through the Metaclass (have a look at your moc_classname.cpp file for more) but most of the interclass communication that you will produce will probably use signals and slots. Signals can get delivers immediately or deferred via a queue (if you are using threads) A signal can be generated

这篇关于Qt事件和信号/插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆