You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Saturday, August 13th 2011, 10:37am

Events not called unless mouse is moving

I have a problem where it appears that events generated by QTimer and QExtSerialPort don't get called unless the mouse moves. It is as though the event loop isn't running unless being fed with mouse move events.

The application structure is as follows. There is a main application derived from QApplication and a main window derived from QMainWindow all in the usual way. There are also widgets e.g. graphWidget which show data graphically which are derived from a fooWidget class which itself is derived from QWidget. In, for example, graphWidget I have a QTimer which updates the graph at a regular interval. The problem is the graph doesn't get updated unless I keep moving the mouse. I.e. the event slot that the QTimer is connected to, isn't executed unless the mouse is moving.

The same is true for the communications class gathering data from the serial port using QExtSerialPort. There is a barWidget class derived from QWidget and a serialComms class derived from barWidget, in the serialComms class there is QExtSerialPort getting data from the serial port but its events slot which is connected to the ReadyRead() signal is also not called unless the mouse is moving.

All the above classes are constructed using 'this' from the mainWindow class.

Has anyone seen this before? Can you shed any light on it please?

Regards
Pete

Junior

Professional

  • "Junior" is male

Posts: 1,623

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

2

Saturday, August 13th 2011, 10:56am

Seems the event slot is eating events and not passing on to parent, are you passing the events on to the parent?

// example //

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
 {
     if (obj == textEdit) {
         if (event->type() == QEvent::KeyPress) {
             QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
             qDebug() << "Ate key press" << keyEvent->key();
             return true;
         } else {
             return false;
         }
     } else {
         // pass the event on to the parent class
         return QMainWindow::eventFilter(obj, event);
     }
 }


Just a thought.

3

Saturday, August 13th 2011, 12:56pm

Thank you for your thoughts. I'm not doing anything regarding event filtering in MainWindow, or in fact anywhere, should I be? I thought, perhaps naively, the Qt magic under the hood would call all child event loops from the MainWindow event loop automatically. The only overloaded event functions in MainWindow are mouseMove, mousePress, mouseRelease and keyPress.

Do I need to overload eventFilter in MainWindow, see which widget the event is for, and despatch it to the widget for processing?

Junior

Professional

  • "Junior" is male

Posts: 1,623

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

4

Sunday, August 14th 2011, 12:10pm

No, I didn't mean it to sound like I was keying on an event filter. I was just trying to point out that it could be that an event isn't being passed along but ignored where you might be trapping for events like keypress.

Quoted

If you reimplement this handler, it is very important that you call the base class implementation if you do not act upon the key.

ref: Widget::KeyPressEvent

5

Monday, August 15th 2011, 9:18am

I've found a few places where I haven't passed the event back to the parent, so I'll look for others, fix them and see if it works...

6

Tuesday, August 16th 2011, 10:41am

I've fixed all the places the event wasn't being passed to the parent but the problem still remains.

The event generated by a QTimer or QExtSerialPort is not being serviced unless the mouse is moving over the application window. If the mouse is moving over a different part of the screen the events don't get called.

Junior

Professional

  • "Junior" is male

Posts: 1,623

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

7

Tuesday, August 16th 2011, 1:12pm

Never can be easy can it.

If your using a code repository (cvs, svn, ... ) I would create a separate branch and use it as a unit test to debug with.

I would probably also try in this situation, create small applications and build up until the problem presents itself.
I would also debug using global event filter for analysis of what the application is processing. Determine if it may be a parent causing this symptom.

One other thing that just came to me, check to see if maybe any window flags might be used to get around this. Not sure what OS your using, but sometimes on Windows, the flags are helplful when creating the widget. -- might not be helpful, but it was something that fired across my synapses just now.

Good Luck