Custom Event Compression



  • 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?



  • 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);
    }
    @



  • Yea, that would work. I didn't see compressEvent in the docs let alone that its a virtual function.



  • Created a bug since this isn't documented."Bug Report":http://bugreports.qt.nokia.com/browse/QTBUG-19711



  • 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.



  • Well, I personally don't see another solution then, but you might find one. Good luck!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.