0
votes

What is the default priority of events under 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." Does it just mean that Qtimer with zero timeout produces events with lowest possible priority? What about non-zero timeouts?

1
What means event priority? The order depends on what is going on. If I click on a button, of course, it will first get mouse click event and not key press one. If I click and then press a key the order will be the same.vahancho
Note that the priority of an event is specified in the call to QCoreApplication::postEvent rather than being an intrinsic part of the QEvent type itself. Hence it's possible for two events of the same type to have different priorities.G.M.

1 Answers

1
votes

QTimer with a zero timeout is not a timer at all. 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.

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). 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. Conversely, Qt::LowEventPriority, or any priority below zero, means that your events will be posted behind all events posted by Qt itself.

Of course the relative priority of your own events will matter, so e.g. 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.