PDA

View Full Version : handling XClientMessageEvent



qtdev18
14th August 2007, 22:55
I'm new to Qt, so I apologize if this is a silly question.

I'm using Qt on Linux. My application gets sent XClientMessageEvent from another application. How does Qt handle these events? Do they get converted to a QCustomEvent?

marcel
15th August 2007, 04:52
Reimplement QWidget::x11Event(XEvent*) and catch it there.

Regards

qtdev18
15th August 2007, 15:47
What if I can't reimplement QWidget::x11Event since the widget is actually created by someone else - I simply get a pointer to a QWidget.

My application (or rather library) has a QObject-derived class which holds a pointer to the QWidget and calls installEventFilter on it. I have reimplemented QObject::eventFilter, but from what I can see, that only works for QEvent, not XClientMessageEvent.

jpn
15th August 2007, 16:07
Perhaps QApplication::x11EventFilter() then?

qtdev18
15th August 2007, 17:38
Same problem - someone else creates QApplication as well!

marcel
15th August 2007, 18:14
Could you be more specific?
Do you have a library, or what?

How do you use the QApplication that is already created by someone else?

Regarding your QObject which you use as an event filter... Couldn't you turn it into a QWidget?

jpn
15th August 2007, 18:20
I think QApplication::x11EventFilter() and QWidget::x11Event() are the only possibilities to access native X11 events. Further than that they get translated as Qt events.

qtdev18
15th August 2007, 19:52
To clarify (hopefully):

I am writing a library that someone else will link into their application. That someone else is the one who will create the QApplication and the QWidget (and any other GUI objects). They will simply pass the QWidget to my library. I have a QObject-derived class that calls installEventFilter on the QWidget that was passed to my library so I can grab the events I need. This works for all events (key and mouse input, focus, etc) except the XClientMessageEvent that also gets sent to the QWidget.

Since Qt seems to translate all the other XEvents correctly, it just seems odd to me that it doesn't translate an XClientMessageEvent to a QCustomEvent as well.

jpn
15th August 2007, 20:16
I am writing a library that someone else will link into their application. That someone else is the one who will create the QApplication and the QWidget (and any other GUI objects). They will simply pass the QWidget to my library. I have a QObject-derived class that calls installEventFilter on the QWidget that was passed to my library so I can grab the events I need.
I'm afraid there is no way for you to catch XClientMessageEvent within the described environment. Perhaps you could write a QApplication subclass which makes it possible for you to catch required native events. Then just demand end-users to instantiate your application object instead of QApplication. If they don't, the particular feature depending on XClientMessageEvent becomes disabled or so.


This works for all events (key and mouse input, focus, etc) except the XClientMessageEvent that also gets sent to the QWidget.

Since Qt seems to translate all the other XEvents correctly, it just seems odd to me that it doesn't translate an XClientMessageEvent to a QCustomEvent as well.
The purpose of QCustomEvent is something completely different, namely user-defined events. I'm not so sure about "all the other XEvents" either. :)