将信号/插槽(QObject)添加到QGraphicsItem:性能受到影响吗? [英] Adding signals/slots (QObject) to QGraphicsItem: performance hit?

查看:204
本文介绍了将信号/插槽(QObject)添加到QGraphicsItem:性能受到影响吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向QGraphicsItem添加信号/插槽,以便可以从另一个线程访问QGraphicsItemObjects。我知道有两个选项:使用QGraphicsObject或从QObject和QGraphicsItem继承。

I want to add signals/slots to a QGraphicsItem so I can reach QGraphicsItemObjects from another thread. There are two options that I know of: use QGraphicsObject or inherit from QObject and QGraphicsItem.

假定这很慢。根据关于stackoverflow QGraphicsObject的此答案,它的运行速度较慢实施。当我查看QGraphicsObjects的来源时,我可以看到根据对对象所做的更改发出了许多信号。在我看来,这似乎是为什么QGraphicsObjects速度慢的一个合理的论点,但我认为第二种解决方案可以避免这种性能下降(如果确实如此)。

This is assumed to be slow. According to this answer on stackoverflow QGraphicsObjects are slow because of their implementation. When I look in the source of QGraphicsObjects I can see a lot of signals being emitted according to changes made to the object. To me this seems a plausible argument for why QGraphicsObjects are slow, but I think this performance hit (if it really is one) can be avoided by the second solution.

在构造从QObject和QGraphicsItem继承的类时,似乎您可以获得QGraphicsObject最有趣的功能,而对性能的影响却不大:您能够在类中定义插槽并发出信号,但是您不必继承QGraphicsObject的默认实现,该实现会在您可能不感兴趣的更改时不断发出信号。您现在可以发出信号,而不必担心信号被为您不关心的事物发出(变化的x值在QGraphicsObject中发出信号,但在此解决方案中不发出信号)。

When constructing a class that inherits from QObject and QGraphicsItem it seems that you get the most interesting feature of QGraphicsObject minus the performance hit: you are able to define slots and emit signals in your class but you don't inherit the default implementation of QGraphicsObject that would constantly emit signals on changes you might not be interested in. You are now able to emit signals but don't have to worry about signals being emitted for things you don't care about (x value that changes emits a signal in QGraphicsObject but not in this solution).


  • QGraphicsObjects真的比QGraphicsItems慢吗?

  • 如果是,是因为实现了mentation发出信号(发出信号会严重打击
    )?

  • 如果是这样,第二种解决方案(多重继承)是否可以避免这种惩罚?

推荐答案

此线程建议另一个选择:创建一个QObject子类以代表QGraphicsItems发出信号。

This thread suggests another option: Create a QObject subclass to emit signals on behalf of your QGraphicsItems.

如果您有许多可以共享一个QObject的QGraphicsItem,那么这将比每个QGraphicsItem继承QObject轻巧。

If you have many QGraphicsItems that can share a single QObject, then this will be lighterweight than having each QGraphicsItem inherit QObject.

这篇关于将信号/插槽(QObject)添加到QGraphicsItem:性能受到影响吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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