I want to invoke a slot of MyWidget
class MyWidget : public QWidget {
Q_OBJECT
public slots:
void onFooBar(const std::string&);/*std::string& could also be replaced
by a QString for easier meta system handling*/
};
But because in my case boost::asio
use, with threads I don't want to have to do anything with Qt, I want to invoke this slot from a thread different from the main thread but a random thread I don't control. (On of the threads I let run boost::asio
of course)
How can I do this? QCoreApplication::postEvent
seems to be a nice choice, but the docs don't point out a nice way, on how to create the necessary QEvent
. QMetaObject::invokeMethod
with Qt::QueuedConnection
seems nice too, but isn't documented as thread safe.
So how can I safely invoke a qt slot from a non qt managed thread?
(Although the title of Boost asio with Qt suggests this could be a duplicate, the question seems completely different to me, this questions is not necessarily connected to boost::asio
)