1

Is it possible to get the time when an event has been scheduled to a QEventLoop (e.g. the QCoreApplication event loop)?

I have a situation where the main event loop is paused. When it's reactivated the events are fired and I am interested in the time when the events where added to the queue. The events are not custom events but system (and other) events.

Regards,

Hyndrix
  • 4,282
  • 7
  • 41
  • 82

1 Answers1

1

It mainly depends on what are the system events you are interested in, for you have already the timestamp in some cases.

As an example, QInputEvent (base class for events that describe user input, like QMouseEvent, QKeyEvent, and so on) has the member method timestamp that:

Returns the window system's timestamp for this event.

In other terms, a timestamp close to the time when it has been pushed into the event loop.

skypjack
  • 49,335
  • 19
  • 95
  • 187
  • I am interested in ``QMetaCallEvent`` for instance (http://code.woboq.org/qt5/qtbase/src/corelib/kernel/qobject_p.h.html#361) which do not have a timestamp. I was already suspecting that there is no generic timestamp when adding it to the central queue due to (in most cases) unnecessary overhead. – Hyndrix Jan 09 '16 at 06:33
  • A second event I am interested in is the ``QTimerEvent`` (http://doc.qt.io/qt-4.8/qtimerevent.html). – Hyndrix Jan 09 '16 at 06:35
  • 1
    To be honest, it seems an XY-problem. What do you want to do exactly? Why you are trying to catch the time when an even has been triggered? – skypjack Jan 09 '16 at 09:45
  • Any idea on how to get a valid timestamp before the timestamp() method was introduced? Unfortunately, I have to use Qt 4.8. for now. – FrozenTarzan Oct 15 '18 at 10:05
  • @FrozenTarzan Unfortunately no, I forgot almost everything related to Qt4 since I started using Qt5. :-) – skypjack Oct 15 '18 at 10:20
  • @skypjack Sure, may I ask if you have any idea on how to do that on an embedded Linux platform? The time I see input events in my event filter is actually to late already since the event got queued (long) before that. I guess that this should not be a comment but I'm not aware of how to open a "chat" and if that is more appropriate^^ – FrozenTarzan Oct 15 '18 at 12:13
  • @FrozenTarzan I'd rather create a dedicated question where you can link this Q/A for further details. There a lot of smart people on SO that can help you. – skypjack Oct 15 '18 at 12:18
  • @skypjack Thanks! I posted a new one: https://stackoverflow.com/questions/52816955/get-the-timestamp-when-a-qinputevent-was-put-onto-the-queue-of-the-qeventloop-in – FrozenTarzan Oct 15 '18 at 12:36
  • @skypjack And since you have pointed to an "XY-problem" in one of your older comments I have posted another question regarding the main goal of my question: https://stackoverflow.com/questions/52817148/how-to-block-ignore-discard-user-input-events-that-are-older-than-a-certain-time – FrozenTarzan Oct 15 '18 at 12:48