Qt C ++在GUI线程(Boost线程)之外显示图像 [英] Qt C++ Displaying images outside the GUI thread (Boost thread)

查看:150
本文介绍了Qt C ++在GUI线程(Boost线程)之外显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用VS2015通过Qt实现其接口的C ++库.在库方面,3个 boost线程连续从3个文件夹中加载图像.我试图在3个不同的 QLabel (或等效的 QWidgets )中显示这些图像,因此线程主体包含此功能, 特别是利用 setPixmap 方法.尽管对函数的调用受增强互斥锁的保护,但我可能由于线程同步而出现了异常.在寻找解决方案时,我已经意识到 QPixmap 小部件不是"线程安全的"(不可重入).我也尝试使用 QGraphicsView ,但是它又依赖于 QPixmap ,因此遇到了同样的问题. 所以我的问题是:是否存在QPixmap的替代方案以在线程安全的情况下在Qt中显示图像 方式?

I am developing a C++ library realizing its interface by means of Qt, using VS2015. On the library side, 3 boost threads continously load images from 3 folders. I am trying to display these images in 3 different QLabel (or equivalent QWidgets), so the thread body consists of this functionality, in particular by exploiting the setPixmap method. Although the call to the function is protected by a boost mutex, I got exceptions probably due to threads synchronization. Looking for a solution, I already awared that the QPixmap widget is not "thread-safe" (non-reentrant). I also tried to use QGraphicsView but it in turn relies on QPixmap, thus I came across the same problem. So my question is: does an alternative to QPixmap exist to display images in Qt in a thread-safe manner?

推荐答案

我使用信号/插槽解决了问题:非GUI"线程发出信号而不是显示图像,被调用的插槽在GUI线程内绘制了QLabel !

I solved using signal/slot: the "non-GUI" thread emits a signal instead of displaying the images and the called slot paints the QLabel inside the GUI thread!

这篇关于Qt C ++在GUI线程(Boost线程)之外显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆