Use QEvent::MetaCall for our own QEvent-derived class
Jakob last edited by
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
QObjectavailable 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 own
OurCallBackEvent, which will use the
Does that make sense? My worry in particular is that it may be not a good idea to use the predefined
QEvent::MetaCalltype. 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 a
QObjectavailable to target.