Custom Event Compression
-
wrote on 3 Jun 2011, 16:47 last edited by
I don't see a way to compress custom event types. Does anyone have a solution or know of a work around for this problem?
-
wrote on 3 Jun 2011, 18:12 last edited by
You have to subclass Q(Core)Application (depending on whether you want gui or not) and then overwrite the compressEvent function. And don't forget to call the parent function at the end so that the standard events are compressed (a little plagarism from QApplication):
@
bool MyApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
{
if(event->type()==MyEventType)
{
for (int i = 0; i < postedEvents->size(); ++i) {
const QPostEvent &cur = postedEvents->at(i);
if (cur.receiver != receiver || cur.event == 0 || cur.event->type() != event->type())
continue;
delete event;
return true;
}
return false;
}
return QCoreApplication::compressEvent(event, receiver, postedEvents);
}
@ -
wrote on 3 Jun 2011, 19:25 last edited by
Yea, that would work. I didn't see compressEvent in the docs let alone that its a virtual function.
-
wrote on 3 Jun 2011, 19:49 last edited by SGaist
Created a bug since this isn't documented."Bug Report":https://bugreports.qt.io/browse/QTBUG-19711
-
wrote on 3 Jun 2011, 20:12 last edited by
Ok after further investigation the above code snippet wont work sort of. You would have to include qthread_p.h to get the definition of QPostEventList and QPostEvent. IMO including private files should be avoided at all costs.
-
wrote on 3 Jun 2011, 23:56 last edited by
Well, I personally don't see another solution then, but you might find one. Good luck!
1/6