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

来源:互联网 发布:sql 加列 编辑:程序博客网 时间:2024/05/01 08:06

例如使用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 *)));

原创粉丝点击