I have a QMainWindow-derived Widget that contains a QGLWidget-derived Widget. I have a custom Event that will get fired from within the GLWidget's paintGL() method that way (the notification shall be asynchonous, that's why I'd like to post an event):
QCoreApplication::postEvent(parent(),new ColpickEvent(rgb, pickPoint));
The event looks like this (very simple, no capsuling of data):
#define COLORPICK_EVENT QEvent::Type(31337)
class ColpickEvent : public QEvent
{
public:
ColpickEvent(QRgb col, const QPoint& pos)
: QEvent(COLORPICK_EVENT), Color(col), PixelPos(pos) {};
QColor Color;
QPoint PixelPos;
};
The MainWindow overrides QObject::event(QEvent*) like this:
#define EVENT_TYPE(ClassName) { ClassName *e = static_cast<ClassName*>(event)
#define END_EVENT } break
#define ACCEPT_EVENT e->accept(); return true
bool MainWindow::event(QEvent* event)
{
switch(event->type())
{
/*... handle other events ...*/
case COLORPICK_EVENT:
EVENT_TYPE(ColpickEvent);
// do something with the data provided by the event ...
ACCEPT_EVENT;
END_EVENT;
/*... handle other events ...*/
}
return QMainWindow::event(event);
}
What happens is, that my ColpickEvent never seems to get dispatched to MainWindow. Any ideas why this happens (or actually doesn't happen)?