Qt 跨线程连接信号槽出现connect成功,不进入槽函数的问题解决

  • Post author:
  • Post category:其他

当图片比较大的时候,获取图像中像素信息的计算耗时可能会增加一点,Debug模式偶尔会从1ms->10ms不等,分辨率是1000万像素的图像,所以做了一个线程去处理。

问题:connect(&m_pixelwork,SIGNAL(PixelInfo(QImage::Format,QColor,int,int,int,int),

this,SLOT(ShowPixel(QImage::Format,QColor,int,int,int,int)));

m_pixelwork是工作类,线程通过moveToThread来运行,连接成功但是不进入槽函数。。。

从网上大神的博客了解到需要用到QueuedConnection

http://www.cnblogs.com/findumars/p/5176419.html

因此默认的方式Auto没有设置成Queue模式,所以改成如下:

qRegisterMetaType<QImage::Format>(“QImage::Format”);
r = connect(&m_pixelwork, SIGNAL(PixelInfo(QImage::Format, QColor, int, int, int, int)),
        this, SLOT(ShowPixel(QImage::Format, QColor, int, int, int, int)),Qt::ConnectionType::QueuedConnection);

改成Queued之后需要对QImage::Format进行注册


版权声明:本文为u010796650原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。