Use QEvent::MetaCall for our own QEvent-derived class
-
We have an application where we mix Qt(5) with some other technologies. In particular, the handling of threads is done through Boost::asio. One of the things that happens often is that we want to post some jobs on a worker thread, but want to make sure that either some signal handler, or some callback is executed on the main thread again. However, not in all scenarios is there some
QObject
available to execute the callback on (in particular, in some rare scenarios the callback could be a global)We have been thinking to create a small wrapper (involving some template magic) that will internally call
QApplication::postEvent(QApplication::instance(), OurCallBackEvent())
. The details I omitted (because I have no idea what they will look like), but the basic idea is to create our ownQEvent
classOurCallBackEvent
, which will use theQEvent::MetaCall
type.Does that make sense? My worry in particular is that it may be not a good idea to use the predefined
QEvent::MetaCall
type. What could go wrong, if anything?Btw: we also looked at
QMetaObject::invokeMethod
, but that doesn't seem to have overloads for function pointer syntax (which we really, really like) and, btw, which also only works when we have aQObject
available to target.