Qt - emit a signal from a c++ thread

后端 未结 4 659
孤独总比滥情好
孤独总比滥情好 2021-01-01 20:04

I want to emit a signal from a C++ thread (std::thread) in Qt.

How can I do it?

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 20:51

    If you're keeping pointer to your QObject then you could use one of QMetaObject::invokeMethod member http://qt-project.org/doc/qt-5/qmetaobject.html#invokeMethod

    Probably you will have to use Qt::QueuedConnection so your signal will be invoked at proper thread (not your std::thread). Remember that your signal won't be invoked immedietly.

提交回复
热议问题