在Qt中線程間connect收不到signal的問題。

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.