1

Qt problem:

I am sending a signal from object A which is running on thread A to object B which is running on thread B. I am also handling custom events by overing virtual event function in Object B.

Problem facing: When object A is emitting any signal , corresponding slot in Object B is not getting invoked instead of that event function which is overridden by object B is getting called.So how to extract arguments send by signal from QEvent object received by event function of Object B or how to defer that event so that corresponding slot gets called.

Object A is running in gui thread and its responsibilty is to update the gui . Object B is implementing gui logic and running in different thread . Object A is notifying gui changes through signals and slots to object B . Object B is also handling events coming from one more thread which is not a QThread . I am using custom events for that and using postEvent() function for that to notify Object B . Object B has overriden event function for receiving custom events. Now the problem is that when i am sending any signal from object A to object B to notify about gui related changes , it is getting caught by event function and the corresponding slot is not getting invoked

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

Your problem is very simple: when overriding the QObject::event method, you must call the base class's implementation. It is, indeed, QObject::event that acts on the QMetaCallEvent and executes the queued method invocation.

You should do as follows:

class MyObject : public QObject {
  Q_OBJECT
protected:
  bool event(QEvent * ev);
  ...
};

bool MyObject::event(QEvent * ev) {
  if (ev->type() == MyEventType) {
    ...
    return ...;
  }
  else
    return QObject::event(ev);
}
Ezee
  • 4,214
  • 1
  • 14
  • 29
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313