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

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

问题描述

我正在开发一个 C++ 库,使用 VS2015 通过 Qt 实现其接口.在库方面,3 个 boost 线程 连续从 3 个文件夹加载图像.我试图在 3 个不同的 QLabel(或等效的 QWidgets)中显示这些图像,因此线程主体包含此功能,特别是通过利用 setPixmap 方法.尽管对该函数的调用受 boost 互斥锁保护,但由于线程同步,我得到了异常.在寻找解决方案时,我已经意识到 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天全站免登陆