简体   繁体   English

Qt中事件的默认优先级

[英]Default priority of events in Qt

What is the default priority of events under Qt? Qt下事件的默认优先级是多少? Are they all have the same priority (which?), or some of them are more equal than others? 它们是否都具有相同的优先级(哪个?),或者其中某些优先级更高? According to the documentation, "As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed." 根据文档,“在特殊情况下,一旦窗口系统的事件队列中的所有事件都已处理,超时为0的QTimer就会超时。” Does it just mean that Qtimer with zero timeout produces events with lowest possible priority? 这是否仅意味着超时为零的Qtimer产生具有最低优先级的事件? What about non-zero timeouts? 非零超时呢?

QTimer with a zero timeout is not a timer at all . 超时为零的QTimer根本不是计时器 It's a misnomer. 这是一个误称。 It doesn't make any sense to have such a timer, so it was overloaded to be a special construct that lets you execute some code when the event queue is empty. 拥有这样的计时器没有任何意义,因此它被重载为一种特殊的结构,可让您在事件队列为空时执行一些代码。 It's has precisely nothing whatsoever to do with any timer handling code, and is internally handled as a special case by Qt. 它与任何计时器处理代码完全无关,并且在Qt内部作为特殊情况进行处理。

By default, all events produced by Qt itself are posted under the default priority of zero (0), and there's no way to change it short of editing Qt code (and there's no reason for that here). 默认情况下,由Qt本身产生的所有事件均以默认优先级零(0)进行发布,除非编辑Qt代码,否则无法对其进行更改(这里没有理由)。 The notion of priority for events only matters if you are posting the events yourself, and then you only really have two choices: Qt::HighEventPriority , or any priority above zero, means that your events will be posted in front of events posted by Qt itself. 事件优先级的概念仅在您自己发布事件时才重要,然后您实际上只有两个选择: Qt::HighEventPriority或任何大于零的优先级,这意味着您的事件将在Qt发布的事件之前发布本身。 Conversely, Qt::LowEventPriority , or any priority below zero, means that your events will be posted behind all events posted by Qt itself. 相反, Qt::LowEventPriority或低于零的任何优先级意味着您的事件将在Qt本身发布的所有事件之后发布。

Of course the relative priority of your own events will matter, so eg your own events with priority 2 will be queued in front of your own events with priority 1. But Qt's own events only ever have priority of 0. 当然,您自己的事件的相对优先级很重要,因此,例如,您自己的优先级为2的事件将在您自己的优先级为1的事件之前排队。但是Qt自己的事件的优先级始终为0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM