Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, September 2007
How to debug loss of XEvents?


Message 1 in thread

I have a small widget that receives certain XEvents (of type ClientMessage)
via an overwritten x11 event filter in  the widget. As a standalone
application this works. However as part of a bigger application, this
ceases to work. The filter gets called, and I can see mouse move events and
similar there, but the ClientMessages are filtered out. Why? What could
cause this? Any ideas where I should look? The rest of the program is lots
of Qt widgets, especially one QGLWidget.

Cheers,

Arne

-- 
 [ signature omitted ] 

Message 2 in thread

Arne Schmitz wrote:

> I have a small widget that receives certain XEvents (of type
> ClientMessage) via an overwritten x11 event filter in  the widget. As a
> standalone application this works. However as part of a bigger
> application, this ceases to work. The filter gets called, and I can see
> mouse move events and similar there, but the ClientMessages are filtered
> out. Why? What could cause this? Any ideas where I should look? The rest
> of the program is lots of Qt widgets, especially one QGLWidget.

Ok, now I found out why it does not work. It is because the widget which
should receive the events is not the toplevel widget. Consider this small
program:

#include <iostream>
#include <QApplication>
#include "SpaceNav.h"

int
main(int argc, char **argv)
{
    QApplication a(argc, argv);

    QWidget *w1 = new QWidget();
    w1->show();

    SpaceNav *w = new SpaceNav(w1);
    w->show();
    return a.exec();
}

Widget w is trying to receive, but it seems that w1 is filtering the events.
If I remove w1, everything works fine. Can I get w to still receive the
events?

Arne

-- 
 [ signature omitted ] 

Message 3 in thread

> -----Original Message-----
> From: Arne Schmitz [mailto:arne.schmitz@xxxxxxx]
> Sent: Wednesday, September 05, 2007 12:13 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: How to debug loss of XEvents?
> 
> Arne Schmitz wrote:
> 
> > I have a small widget that receives certain XEvents (of type
> > ClientMessage) via an overwritten x11 event filter in  the widget. As a
> > standalone application this works. However as part of a bigger
> > application, this ceases to work. The filter gets called, and I can see
> > mouse move events and similar there, but the ClientMessages are filtered
> > out. Why? What could cause this? Any ideas where I should look? The rest
> > of the program is lots of Qt widgets, especially one QGLWidget.
> 
> Ok, now I found out why it does not work. It is because the widget which
> should receive the events is not the toplevel widget. Consider this small
> program:
> 
> #include <iostream>
> #include <QApplication>
> #include "SpaceNav.h"
> 
> int
> main(int argc, char **argv)
> {
>     QApplication a(argc, argv);
> 
>     QWidget *w1 = new QWidget();
>     w1->show();
> 
>     SpaceNav *w = new SpaceNav(w1);
>     w->show();
>     return a.exec();
> }
> 
> Widget w is trying to receive, but it seems that w1 is filtering the
> events.
> If I remove w1, everything works fine. Can I get w to still receive the
> events?
> 
> Arne
> 

I think you may want to put the filter on the QApplication and decide who needs it based on sending out a custom QEvent 

Scott

--
 [ signature omitted ] 

Message 4 in thread

Scott Aron Bloom wrote:

> I think you may want to put the filter on the QApplication and decide who
> needs it based on sending out a custom QEvent

I cannot do this. The widget has to be the one who does this. I cannot 
replace the QApplication object in the application. Any other ideas?

Arne

-- 
 [ signature omitted ] 

Message 5 in thread

Arne Schmitz wrote:

> Scott Aron Bloom wrote:
> 
>> I think you may want to put the filter on the QApplication and decide who
>> needs it based on sending out a custom QEvent
> 
> I cannot do this. The widget has to be the one who does this. I cannot
> replace the QApplication object in the application. Any other ideas?
Install an eventfilter on QApplication? No need to actually replace
QApplication. You can make your widget act as the EventFilter, if you like.
See void QObject::installEventFilter ( QObject * filterObj ) in the docs
for details.

André


André
-- 
 [ signature omitted ] 

Message 6 in thread

André Somers wrote:

>> I cannot do this. The widget has to be the one who does this. I cannot
>> replace the QApplication object in the application. Any other ideas?
>
> Install an eventfilter on QApplication? No need to actually replace
> QApplication. You can make your widget act as the EventFilter, if you
> like. See void QObject::installEventFilter ( QObject * filterObj ) in the
> docs for details.

Hm, ok. I will try and see if that helps. I do not yet see how, but I will
try. :)

Arne

-- 
 [ signature omitted ] 

Message 7 in thread

André Somers wrote:

>> I cannot do this. The widget has to be the one who does this. I cannot
>> replace the QApplication object in the application. Any other ideas?
>
> Install an eventfilter on QApplication? No need to actually replace
> QApplication. You can make your widget act as the EventFilter, if you
> like. See void QObject::installEventFilter ( QObject * filterObj ) in the
> docs for details.

Ok, I browsed through the docs for this. However it seems, that XEvents are
received, given to the toplevel widgets, and if not processed, converted to
QEvents. However those ClientMessages are not converted, as far as I can
see. So I think this does not help me...

Arne

-- 
 [ signature omitted ] 

Message 8 in thread

Hi,

> Ok, I browsed through the docs for this. However it seems, that XEvents are
> received, given to the toplevel widgets, and if not processed, converted to
> QEvents. However those ClientMessages are not converted, as far as I can
> see. So I think this does not help me...

Can't you convert these ClientMessages XEvents to QEvents yourself in an 
application-wide event filter?

--
 [ signature omitted ] 

Message 9 in thread

> Hi,
> 
> > Ok, I browsed through the docs for this. However it seems, that
XEvents
> are
> > received, given to the toplevel widgets, and if not processed,
converted
> to
> > QEvents. However those ClientMessages are not converted, as far as I
can
> > see. So I think this does not help me...
> 
> Can't you convert these ClientMessages XEvents to QEvents yourself in
an
> application-wide event filter?
> 
> --
> Dimitri
> 
I think the issue is, since the ClientMessage is not propagated to the
qevent system, the event filter will not get there... And since the
widget with the x11Events method is not getting the x11 events, it cant
be converted.

Scott

--
 [ signature omitted ] 

Message 10 in thread

Scott Aron Bloom wrote:

> I think the issue is, since the ClientMessage is not propagated to the
> qevent system, the event filter will not get there... And since the
> widget with the x11Events method is not getting the x11 events, it cant
> be converted.

Ok, just as a notice: What works is to create a toplevel widget and never
show() it. This way I still receive those events.

Arne

-- 
 [ signature omitted ] 

Message 11 in thread

Sorry... I did a reply all.. and should of kept it to the list only...

Why cant you replace the QApplication?  

Another option... Have the x11Event method in the widget convert the X11
event to a QEvent, and install QT event filters to "read" the events...

Or maybe... create a "MyTopLevelWidget" class base class for your app,
which all your possible top level widgets derive from.

And have the X11 event handled, and sent to all other top level widgets.

Scott

> -----Original Message-----
> From: Arne Schmitz [mailto:arne.schmitz@xxxxxxx]
> Sent: Wednesday, September 05, 2007 12:16 PM
> To: Scott Aron Bloom
> Subject: Re: How to debug loss of XEvents?
> 
> Am Mittwoch, 5. September 2007 21:15 schrieben Sie:
> > I think you may want to put the filter on the QApplication and
decide
> who
> > needs it based on sending out a custom QEvent
> 
> Damn. I cannot do this. The widget has to be the one who does this. I
> cannot
> replace the QApplication object in the application. Any other ideas?
> 
> Arne
> 
> --
> Dipl.-Inform. Arne Schmitz              Phone   +49 (0)241 80-21817
> Computer Graphics Group                 Fax     +49 (0)241 80-22899
> RWTH Aachen University                  http://www.rwth-graphics.de
> Ahornstrasse 55, 52074 Aachen, Germany

--
 [ signature omitted ] 

Message 12 in thread

Scott Aron Bloom wrote:

> Sorry... I did a reply all.. and should of kept it to the list only...
> 
> Why cant you replace the QApplication?

Because it is supposed to be used in already existing applications, where I
cannot change the source to use my derived QApplication class.
 
> Another option... Have the x11Event method in the widget convert the X11
> event to a QEvent, and install QT event filters to "read" the events...

Well, how would that work, if the XEvents do not reach my widget?

> Or maybe... create a "MyTopLevelWidget" class base class for your app,
> which all your possible top level widgets derive from.
> 
> And have the X11 event handled, and sent to all other top level widgets.

Same as the first...

Another possibility: Can I reparent all widgets to be a child of my new
widget? That would solve the problem, too...

Arne

-- 
 [ signature omitted ] 

Message 13 in thread


> Scott Aron Bloom wrote:
> 
> > Sorry... I did a reply all.. and should of kept it to the list
only...
> >
> > Why cant you replace the QApplication?
> 
> Because it is supposed to be used in already existing applications,
where
> I
> cannot change the source to use my derived QApplication class.
> 
> > Another option... Have the x11Event method in the widget convert the
X11
> > event to a QEvent, and install QT event filters to "read" the
events...
> 
> Well, how would that work, if the XEvents do not reach my widget?
> 
> > Or maybe... create a "MyTopLevelWidget" class base class for your
app,
> > which all your possible top level widgets derive from.
> >
> > And have the X11 event handled, and sent to all other top level
widgets.
> 
> Same as the first...
> 
> Another possibility: Can I reparent all widgets to be a child of my
new
> widget? That would solve the problem, too...
> 
> Arne

Ahh.. one of those... instantiate me, and all your problems go away
classes :)

Well.. I would approach it like this, install an event filter on
QApplication (and possible all top level widgets)

qApp->installEventFilter( this )

and then in your widget, implement the eventFilter( QOjbect *, QEvent *
) method.

You will have to handle when the QObject is the QApp as well as the the
QWidget derived class in question.

Unfortunately, I'm not sure this will help out...  If the "other"
qwidget is blocking the XEvent, your going to have to install it on all
the top level widgets.

And if it's a X11 event that is NOT converted to a QEvent, you may be
SOL

Meaning, if it's a keyboard, or mouse, or graphics event, you might be
clean... but if it's an event that QT is throwing away, it will never
get to the event filter mechanism,

Scott

--
 [ signature omitted ]