派生的Python对象的深拷贝
我在 python 中有一个对象,它派生自 QtGui.QGraphicsPixmapItem
,具有一些基本属性和方法。在对此对象的引用调用 deepcopy
后,当我尝试使用副本时,我收到一条错误消息,指出底层 C/C++ 对象已被删除
。我之前收到过这个错误,当我没有在 __init__ 中调用基类的构造函数时,就会发生这个错误,所以我认为这个错误是因为 QtGui.QGraphicsPixmapItem
不是被复制。
我该如何指定这一点?我所知道的是有一个用于此目的的 __deepcopy__ 方法。
I have an object in python that is derived from QtGui.QGraphicsPixmapItem
with a few basic attributes and methods. After calling deepcopy
on a reference to this object, I get an error saying that underlying C/C++ object has been deleted
when I try to use the copy. I had received this error before, and it occured when I didn't call the base class' constructor in __init__
so I assume this error is because the QtGui.QGraphicsPixmapItem
is not being copied.
How do I go about specifying this? All I know is that there is a __deepcopy__
method for this purpose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QGraphicsPixmapItem
不可复制。它继承了使用Q_DISABLE_COPY
宏声明的QGraphicsItem
,该宏与QObjects
用于禁用复制的机制相同。 文档对此进行了更好的解释。QGraphicsPixmapItem
is not copyable. It inheritsQGraphicsItem
which is declared using theQ_DISABLE_COPY
macro which is the same mechanism used forQObjects
to disable copying. The documentation explains it a bit better.