Remove all previous mouse event
-
I create Qt application that run qml view, then i pause this application (with linux command kill -STOP id).
when the application is in stop mode i touch the screen, and when I continue the application(with linux command kill -CONT id), I get all the mouse events since the stop time. How can I prevent this situation, I need to come back to the qml application when their is no mouseEvenet?
BTW: I know when I get the CONT event, and at this time I tried to remove all the events, but it didn't work:
@
// Both commands didn't remove the mouse events
m_view->rootObject()->removeEventFilter(m_view->rootObject());
m_view->rootObject()->removeSceneEventFilter(m_view->rootObject());@ -
Read this: "The Event System":http://doc.qt.digia.com/4.7-snapshot/eventsandfilters.html
I think global "Event Filters":http://doc.qt.digia.com/4.7-snapshot/eventsandfilters.html#event-filters can help you... -
I think you may be getting the CONT before the eventloop actually starts processing the events again. How do you get that CONT 'event'? It is an interrupt perhaps?
If the above is correct (it is just a guess!), then what you might do is use that moment to post a custom event to your queue. You use that event as a 'marker' so that you know that any event before it should be treated as invalid. Only when you receive the custom event do you then remove the event filter that disgards the mouse events.
Anyway, the above is not something I have tried myself! No idea if it makes any sense or not.
-
In linux you can be noted for system signals, and this is what I do:
@
void listenToSignals()
{
struct sigaction myAction;
memset(&myAction, '\0', sizeof(myAction));
myAction.sa_handler = removeMouseSignalsFunc;
if(0 > sigaction(SIGCONT, &myAction, NULL))
{
qDebug()<< "sigaction for listenToSignals failed";
}
}static void removeMouseSignalsFunc(int _signum)
{
if(SIGCONT == _signum)
{
qDebug()<<"SIGCONT signal caught.\n";// Here I need to block all the unwanted evenets. }
}
@now I try to figure out how to remove the event filter...
-
I think you should try the approach I sketched out earlier: post a custom event in your removeMouseEventsSignalsFunc, and remove your filter on receiving of that event.
-
Hi Andre,
how can I remove the filter on receiving of that event?
And also prevent the qml to use this mouse events before? -
Well, assuming the eventfilter worked in the first place (I don't know that, you tested that right?), you could do something like this:
@
//header
class EventEater: public QObject {
Q_OBJECT
public:
void EventEater(QObject* parent);
bool isActive() const {return m_isActive;}bool eventFilter(QObject* o, QEvent* e);
public slots:
void activate() (m_active = true;}
void postUnlockEvent();private:
bool m_isActive; // flag to indicate current state
QSetQEvent::Type m_eventList; // list of events to filter out
int m_eventType; // the eventtype used for deactivation
}//cpp file
#include <QApplication>
EventEater::EventEater(QObject* parent) :
QObject(parent),
m_isActive(false),
m_eventType(QEvent::User + 1) // probably should initialize once using QEvent::registerEventType
{
m_eventList << QEvent::MouseButtonDblClick
<< QEvent::MouseButtonPress
<< QEvent::MouseButtonRelease
<< QEvent::MouseMove; //you might add other filters tooqApp->installEventFilter(this);
}
bool EventEater::eventFilter(QObject* o, QEvent* e)
{
if (e && m_isActive) {
if (m_eventList.contains(e->type())) {
return true; //filter out the event, we do not allow it to be handled
}if (e->type() == m_eventType) { m_active = false; // disable the event filter! return true; }
}
return QObject::eventFilter(o, e);
}void EventEater::postUnlockEvent()
{
QEvent* e = new QEvent(m_eventType); //eventloop will take ownership of e
qApp->postEvent(e);
}
@Something like the above (untested, typed directly in forum editor) would work, I think. If you can activate on going into pause, that would work, but it could also work to activate and then immediately call postUnlockEvent when waking up again.
You can also, as an alternative, completely destroy the events in the queue by using QCoreApplication::removePostedEvents()
-
Thank you, it works with the eventFilter() function