现在的位置: 首页 > 综合 > 正文

在Qt中线程间connect收不到signal的问题。

2013年09月07日 ⁄ 综合 ⁄ 共 744字 ⁄ 字号 评论关闭

例如使用QObject::connect( video_frame_process, SIGNAL(ImageReady(cv::Mat )),this, SLOT(ShowImage(cv::Mat)));

编译没问题,但运行的时候发现收不到ImageReady的signal,没有触发ShowImage,查看debug的output会看到

Make sure 'cv::Mat' is registered using qRegisterMetaType()

 

修改的做法参考:

http://stackoverflow.com/questions/9646110/how-to-send-a-qt-signal-containing-a-cvmat

“You need to call
qRegisterMetaType
in addition to the macro (or instead of it, depending on your needs). This is necessary for the signals to be able to marshal your data across threads. However, it might be a wiser idea to pass by reference or smart pointer, or raw pointer
if you are using the QObject hierarchy to manage the object lifetime.”

 

也就是说要么注册cv::Mat 类型,要么使用已经可以识别的类型,如可以改成使用指针传递参数:

QObject::connect( video_frame_process, SIGNAL(ImageReady(cv::Mat  *)),this, SLOT(ShowImage(cv::Mat *)));

抱歉!评论已关闭.