是QPixmap可重入吗? [英] Is QPixmap reentrant?

查看:337
本文介绍了是QPixmap可重入吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序需要加载很多的QPixmaps。我使用 QtConcurrent :: mappedReduced (我实际上加载一堆 QGraphicPixmapItem )。加载函数仅调用 QPixmap s / QGraphicItem 的构造函数,不尝试执行任何绘图,它不与世界其他地方(至少通过我的代码),直到加载完成通信。

I have a program that needs to load a lot of QPixmaps. I split the loading of the pixmaps in several jobs using QtConcurrent::mappedReduced (I actually load a bunch of QGraphicPixmapItems). The loading function calls only the constructors of the QPixmaps/QGraphicItems, it does not attempt to perform any drawing, and it does not communicate with the rest of the world (at least through my code) until the loading is finished.

在初始化期间(例如1%的时间),我收到一些随机崩溃,helgrind抱怨对<$ c $来自 QPixmap 和来自主要事件循环的Q> QApplication ,但是已知Qt互斥体通常不能与valgrind混合,因此可能是假阳性。

I get some random crashes during the initialization (say 1% of the times), and helgrind complains about unguarded accesses to QApplication from the QPixmap and from the main event loop, but it is known that Qt mutexes generally do not mix well with valgrind, so it might be a false positive.

像往常一样,Qt文档对于 QPixmap 是否可重入是不太清楚的,这基本上是我的问题。

As usual, the Qt documentation is quite unclear on whether QPixmap is reentrant or not, that is basically my question.

推荐答案

你已经知道答案了。这不行。

Well, you get crashes and you ask if it's OK? You already know the answer. It's not OK.

我看到的唯一问题是它是一个Qt错误。不,它不是。

The only question I see here is whether it's a Qt bug. No, it's not.

如果你想加载很多像素图,加载到 QImages 然后将它们转换为后备存储格式。有没有这么多的获得这些天,使用像素图在图像上。只要图像具有与窗口小部件的后备存储(转换为 QImage )相同的格式,您将具有相同的性能。当Qt仍然使用本地绘画时, QPixmap 的区别是有意义的。在Windows和OS X上,像素图只是一个正确格式化的 QImage

If you want to load a lot of pixmaps, load them in into QImages, and then convert them into the backing store format. There isn't all that much to be gained these days from using a pixmap over an image. As long as the image has the same format as the widget's backing store (cast to QImage), you'll have same performance. The QPixmap distinction made sense when Qt still used native painting. On Windows and OS X, a pixmap is just a properly formatted QImage.

这篇关于是QPixmap可重入吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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