QML 不拥有从 PyQt 插槽接收的对象的所有权 [英] QML not taking ownership of object received from PyQt slot

查看:30
本文介绍了QML 不拥有从 PyQt 插槽接收的对象的所有权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 QML 调用 Python 函数的正确方法是什么,该函数将实例化并将对象返回给 QML,并且让 QML 端负责对象的生命周期?我面临的问题是对象在到达 QML 之前就被垃圾收集了.

请注意,我不想在 Python 端保留对对象的显式引用,并且根据 文档 我正在寻找的甚至应该是默认行为:

<块引用>

当数据从 C++ 转移到 QML 时,数据的所有权始终保留在 C++ 中.这个规则的例外是当 QObject从显式 C++ 方法调用返回:在这种情况下,QML引擎承担对象的所有权...

我创建了一个最小的可运行示例来演示该问题(要点链接)::>

main.py:

#!/usr/bin/env python# -*- 编码:utf-8 -*-导入操作系统导入系统输入信号从 PyQt5.QtGui 导入 QGuiApplication从 PyQt5.QtQuick 导入 QQuickView从 PyQt5.QtCore 导入 QUrl、QObject、QVariant、pyqtSlot从 PyQt5.QtQml 导入 QQmlEngine, qmlRegisterType类虚拟(QObject):def __del__(self):打印(已删除")类 GUIEntryPoint(QObject):@pyqtSlot(result=QVariant)def get_foo(self):foo = 虚拟()打印(创建{}".格式(foo))print("实例化后的所有权:{}".format(QQmlEngine.objectOwnership(foo)))#QQmlEngine.setObjectOwnership(foo, 1) # 没有效果返回 foo@pyqtSlot(QVariant)def print_foo(self, foo):打印({},所有权:{}".格式(foo,QQmlEngine.objectOwnership(foo)))定义运行():信号.信号(信号.SIGINT,信号.SIG_DFL)app = QGuiApplication(sys.argv)#这些似乎没什么区别qmlRegisterType(GUIEntryPoint, 'GUIEntryPoint', 1, 0, 'GUIEntryPoint')qmlRegisterType(Dummy, 'Dummy', 1, 0, 'Dummy')qml_url = QUrl.fromLocalFile(os.path.join('zzz.qml'))视图 = QQuickView()gep = GUIEntryPoint()view.rootContext().setContextProperty('BE', gep)view.setSource(qml_url)视图.show()sys.exit(app.exec_())如果 __name__ == '__main__':跑步()

zzz.qml:

导入QtQuick 2.2长方形 {id:根项目宽度:640高度:400属性 var pleaseKeepMe: BE.get_foo()Component.onCompleted:{console.log("完成");BE.print_foo(pleaseKeepMe);//打印无,已删除console.log("创建另一个");var x = BE.get_foo();//此时x已经在Python端被删除了console.log("创建了另一个");BE.print_foo(x);//打印无console.log("\n\n按 CTRL-C 退出");}}

解决方案

简而言之:使用 SIP Python API 将所有权转移到 C++,同时保持 QObject 的 Python部分"活着似乎解决了这个问题,这确实是所有权一,如(另请参阅以下来源中的评论)所述:

关于 SIP API,请参阅:

此外,一些不错的一般建议位于:

这个问题的一个稍微修改过的例子,Python 源代码:

from PyQt5.QtGui import QGuiApplication从 PyQt5.QtQuick 导入 QQuickView从 PyQt5.QtCore 导入 QUrl、QObject、QVariant、pyqtSlot从 PyQt5.QtQml 导入 QQmlEngine, qmlRegisterType进口 sip定义所有权(对象):jsOwned = QQmlEngine.objectOwnership(obj) == QQmlEngine.JavaScriptOwnership如果 jsOwned 返回Javascript",否则返回Cpp"def onDummytDestroyed():打印虚拟销毁"类虚拟(QObject):我 = 0def __init__(self):#不要忘记正确初始化基础部分super(Dummy, self).__init__()self.i = Dummy.iDummy.i = Dummy.i + 1def __del__(self):#让我们跟踪 Python 部分何时被销毁#(或者,更确切地说,最终确定",或者任何正确的术语:))打印 "Dummy.__del__(), self.i:", self.i@pyqtSlot(result="QString")def get_str(self):#让我们在类中有一个 Python(不是 C++)实现的方法返回虚拟字符串#"+ str(self.i)类 GUIEntryPoint(QObject):def __init__(self):#与 Dummy.__init__ 相同super(GUIEntryPoint, self).__init__()@pyqtSlot(result=QVariant) #也可以#@pyqtSlot(result=QObject)def get_foo(self):打印GUIEntryPoint.get_foo():"foo = 虚拟()foo.setObjectName("Foo")#让我们跟踪 C++ 部分何时被销毁foo.destroyed.connect(onDummytDestroyed)#this 将在引用后立即销毁 foo 的 Python 部分#goes 超出范围(C++ 部分保持活动状态并且可以从 QML 正确访问,#but 尝试访问 Python 实现的方法,如 Dummy.get_str()# 会导致 TypeError 提示没有这样的方法)#sip.transferto(foo, None)#this 可以正常工作,同时使用 foo 的 Python(然后是 C++)部分#在 QML GC 决定摆脱对象时被销毁#(见程序输出,注意GC是如何静默一段时间的)sip.transferto(foo, foo)#这确实不需要,因为将设置适当的所有权#当对象通过槽调用传递到QML地时#QQmlEngine.setObjectOwnership(foo, QQmlEngine.JavaScriptOwnership)打印初始所有权:",所有权(foo)返回 foo@pyqtSlot(QObject) #也可以#@pyqtSlot(QVariant)def print_foo(self, foo):打印GUIEntryPoint.print_foo():"打印对象名称:",foo.objectName()在 QML 端打印所有权:",所有权(foo)app = QGuiApplication([])视图 = QQuickView()#不需要,事实上,作为上下文对象(和属性),#和传递给QML端的QObject后代是完全可以访问的#(即它们的属性和可调用对象/插槽是)#无需任何额外步骤#(虽然,声明性地实例化类型需要先注册它们,#并且具有自定义类型的属性需要声明元类型)#qmlRegisterType(GUIEntryPoint, 'GUIEntryPoint', 1, 0, 'GUIEntryPoint')#qmlRegisterType(Dummy, 'Dummy', 1, 0, 'Dummy')gep = GUIEntryPoint()view.rootContext().setContextProperty('BE', gep)view.setSource(QUrl.fromLocalFile("pyqt-ownership-test.qml"))视图.show()app.exec_()

QML 源码(另存为 pyqt-ownership-test.py):

导入QtQuick 2.1长方形 {宽度:300高度:200红色"边框宽度:10Component.onCompleted:{console.log("Component.onCompleted():")//将数字增加到 1000 以查看 GC 介入//当循环仍在运行时//(注意某些对象没有报告销毁,//例如,#249(最后创建的),//但这看起来像一个 Qt/QML 日志问题)for (var i = 0; i <250; i++) {console.log("#" + i)var foo = BE.get_foo()console.log(" foo: " + foo)console.log(" foo.objectName: " + foo.objectName)console.log(" foo.get_str():" + foo.get_str())console.log(" print_foo():")BE.print_foo(foo)}}}

程序输出(在中间剥离以适应 SO 答案大小限制):

Component.onCompleted():#0GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x22903d0,富")foo.objectName: Foofoo.get_str(): 虚拟字符串#0打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#1GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x2290d20,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #1打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#2GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x2291080,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #2打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#3GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x22911e0,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #3打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#4GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x2291e90,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #4打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#5GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x2292b70,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #5打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#6GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x2293420,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #6打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#7GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x2296e30,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #7打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#8GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x22983b0,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #8打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#9GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x2299150,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #9打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#10GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x2299e60,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #10打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript#11GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x229ab70,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #11打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript<...这里跳过了一些行...>#245GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x23007b0,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #245打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript第246章GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x22fe4d0,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #246打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript第247章GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x22fc5c0,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #247打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript第248章GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x22fa730,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #248打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:Javascript第249章GUIEntryPoint.get_foo():初始所有权:Cpp富:虚拟(0x22f57b0,富")foo.objectName: Foofoo.get_str(): 虚拟字符串 #249打印_foo():GUIEntryPoint.print_foo():对象名称:FooQML 方面的所有权:JavascriptDummy.__del__(), self.i: 214假人被摧毁Dummy.__del__(), self.i: 213假人被摧毁Dummy.__del__(), self.i: 212假人被摧毁Dummy.__del__(), self.i: 211假人被摧毁Dummy.__del__(), self.i: 210假人被摧毁Dummy.__del__(), self.i: 209假人被摧毁Dummy.__del__(), self.i: 208假人被摧毁Dummy.__del__(), self.i: 207假人被摧毁Dummy.__del__(), self.i: 206假人被摧毁Dummy.__del__(), self.i: 205假人被摧毁Dummy.__del__(), self.i: 204假人被摧毁Dummy.__del__(), self.i: 203假人被摧毁Dummy.__del__(), self.i: 202假人被摧毁Dummy.__del__(), self.i: 201假人被摧毁Dummy.__del__(), self.i: 200假人被摧毁Dummy.__del__(), self.i: 199假人被摧毁Dummy.__del__(), self.i: 198假人被摧毁Dummy.__del__(), self.i: 197假人被摧毁Dummy.__del__(), self.i: 196假人被摧毁Dummy.__del__(), self.i: 195假人被摧毁Dummy.__del__(), self.i: 194假人被摧毁Dummy.__del__(), self.i: 193假人被摧毁Dummy.__del__(), self.i: 192假人被摧毁Dummy.__del__(), self.i: 191假人被摧毁Dummy.__del__(), self.i: 190假人被摧毁Dummy.__del__(), self.i: 189假人被摧毁Dummy.__del__(), self.i: 188假人被摧毁Dummy.__del__(), self.i: 187假人被摧毁Dummy.__del__(), self.i: 186假人被摧毁Dummy.__del__(), self.i: 185假人被摧毁Dummy.__del__(), self.i: 184假人被摧毁Dummy.__del__(), self.i: 183假人被摧毁Dummy.__del__(), self.i: 182假人被摧毁Dummy.__del__(), self.i: 181假人被摧毁Dummy.__del__(), self.i: 180假人被摧毁Dummy.__del__(), self.i: 179假人被摧毁Dummy.__del__(), self.i: 178假人被摧毁Dummy.__del__(), self.i: 177假人被摧毁Dummy.__del__(), self.i: 176假人被摧毁Dummy.__del__(), self.i: 175假人被摧毁Dummy.__del__(), self.i: 174假人被摧毁Dummy.__del__(), self.i: 173假人被摧毁Dummy.__del__(), self.i: 172假人被摧毁Dummy.__del__(), self.i: 171假人被摧毁Dummy.__del__(), self.i: 170假人被摧毁Dummy.__del__(), self.i: 169假人被摧毁Dummy.__del__(), self.i: 168假人被摧毁Dummy.__del__(), self.i: 167假人被摧毁Dummy.__del__(), self.i: 166假人被摧毁Dummy.__del__(), self.i: 165假人被摧毁Dummy.__del__(), self.i: 164假人被摧毁Dummy.__del__(), self.i: 163假人被摧毁Dummy.__del__(), self.i: 162假人被摧毁Dummy.__del__(), self.i: 161假人被摧毁Dummy.__del__(), self.i: 160假人被摧毁Dummy.__del__(), self.i: 159假人被摧毁Dummy.__del__(), self.i: 158假人被摧毁Dummy.__del__(), self.i: 157假人被摧毁Dummy.__del__(), self.i: 156假人被摧毁Dummy.__del__(), self.i: 155假人被摧毁Dummy.__del__(), self.i: 154假人被摧毁Dummy.__del__(), self.i: 153假人被摧毁Dummy.__del__(), self.i: 152假人被摧毁Dummy.__del__(), self.i: 151假人被摧毁Dummy.__del__(), self.i: 150假人被摧毁Dummy.__del__(), self.i: 149假人被摧毁Dummy.__del__(), self.i: 148假人被摧毁Dummy.__del__(), self.i: 147假人被摧毁Dummy.__del__(), self.i: 146假人被摧毁Dummy.__del__(), self.i: 145假人被摧毁Dummy.__del__(), self.i: 144假人被摧毁Dummy.__del__(), self.i: 143假人被摧毁Dummy.__del__(), self.i: 142假人被摧毁Dummy.__del__(), self.i: 141假人被摧毁Dummy.__del__(), self.i: 140假人被摧毁Dummy.__del__(), self.i: 139假人被摧毁Dummy.__del__(), self.i: 138假人被摧毁Dummy.__del__(), self.i: 137假人被摧毁Dummy.__del__(), self.i: 136假人被摧毁Dummy.__del__(), self.i: 135假人被摧毁Dummy.__del__(), self.i: 134假人被摧毁Dummy.__del__(), self.i: 133假人被摧毁Dummy.__del__(), self.i: 132假人被摧毁Dummy.__del__(), self.i: 131假人被摧毁Dummy.__del__(), self.i: 130假人被摧毁Dummy.__del__(), self.i: 129假人被摧毁Dummy.__del__(), self.i: 128假人被摧毁Dummy.__del__(), self.i: 127假人被摧毁Dummy.__del__(), self.i: 126假人被摧毁Dummy.__del__(), self.i: 125假人被摧毁Dummy.__del__(), self.i: 124假人被摧毁Dummy.__del__(), self.i: 123假人被摧毁Dummy.__del__(), self.i: 122假人被摧毁Dummy.__del__(), self.i: 121假人被摧毁Dummy.__del__(), self.i: 120假人被摧毁Dummy.__del__(), self.i: 119假人被摧毁Dummy.__del__(), self.i: 118假人被摧毁Dummy.__del__(), self.i: 117假人被摧毁Dummy.__del__(), self.i: 116假人被摧毁Dummy.__del__(), self.i: 115假人被摧毁Dummy.__del__(), self.i: 114假人被摧毁Dummy.__del__(), self.i: 113假人被摧毁Dummy.__del__(), self.i: 112假人被摧毁Dummy.__del__(), self.i: 111假人被摧毁Dummy.__del__(), self.i: 110假人被摧毁Dummy.__del__(), self.i: 109假人被摧毁Dummy.__del__(), self.i: 108假人被摧毁Dummy.__del__(), self.i: 107假人被摧毁Dummy.__del__(), self.i: 106假人被摧毁Dummy.__del__(), self.i: 105假人被摧毁Dummy.__del__(), self.i: 104假人被摧毁Dummy.__del__(), self.i: 103假人被摧毁Dummy.__del__(), self.i: 102假人被摧毁Dummy.__del__(), self.i: 101假人被摧毁Dummy.__del__(), self.i: 100假人被摧毁Dummy.__del__(), self.i: 99假人被摧毁Dummy.__del__(), self.i: 98假人被摧毁Dummy.__del__(), self.i: 97假人被摧毁Dummy.__del__(), self.i: 96假人被摧毁Dummy.__del__(), self.i: 95假人被摧毁Dummy.__del__(), self.i: 94假人被摧毁Dummy.__del__(), self.i: 93假人被摧毁Dummy.__del__(), self.i: 92假人被摧毁Dummy.__del__(), self.i: 91假人被摧毁Dummy.__del__(), self.i: 90假人被摧毁Dummy.__del__(), self.i: 89假人被摧毁Dummy.__del__(), self.i: 88假人被摧毁Dummy.__del__(), self.i: 87假人被摧毁Dummy.__del__(), self.i: 86假人被摧毁Dummy.__del__(), self.i: 85假人被摧毁Dummy.__del__(), self.i: 84假人被摧毁Dummy.__del__(), self.i: 83假人被摧毁Dummy.__del__(), self.i: 82假人被摧毁Dummy.__del__(), self.i: 81假人被摧毁Dummy.__del__(), self.i: 80假人被摧毁Dummy.__del__(), self.i: 79假人被摧毁Dummy.__del__(), self.i: 78假人被摧毁Dummy.__del__(), self.i: 77假人被摧毁Dummy.__del__(), self.i: 76假人被摧毁Dummy.__del__(), self.i: 75假人被摧毁Dummy.__del__(), self.i: 74假人被摧毁Dummy.__del__(), self.i: 73假人被摧毁Dummy.__del__(), self.i: 72假人被摧毁Dummy.__del__(), self.i: 71假人被摧毁Dummy.__del__(), self.i: 70假人被摧毁Dummy.__del__(), self.i: 69假人被摧毁Dummy.__del__(), self.i: 68假人被摧毁Dummy.__del__(), self.i: 67假人被摧毁Dummy.__del__(), self.i: 66假人被摧毁Dummy.__del__(), self.i: 65假人被摧毁Dummy.__del__(), self.i: 64假人被摧毁Dummy.__del__(), self.i: 63假人被摧毁Dummy.__del__(), self.i: 62假人被摧毁Dummy.__del__(), self.i: 61假人被摧毁Dummy.__del__(), self.i: 60假人被摧毁Dummy.__del__(), self.i: 59假人被摧毁Dummy.__del__(), self.i: 58假人被摧毁Dummy.__del__(), self.i: 57假人被摧毁Dummy.__del__(), self.i: 56假人被摧毁Dummy.__del__(), self.i: 55假人被摧毁Dummy.__del__(), self.i: 54假人被摧毁Dummy.__del__(), self.i: 53假人被摧毁Dummy.__del__(), self.i: 52假人被摧毁Dummy.__del__(), self.i: 51假人被摧毁Dummy.__del__(), self.i: 50假人被摧毁Dummy.__del__(), self.i: 49假人被摧毁Dummy.__del__(), self.i: 48假人被摧毁Dummy.__del__(), self.i: 47假人被摧毁Dummy.__del__(), self.i: 46假人被摧毁Dummy.__del__(), self.i: 45假人被摧毁Dummy.__del__(), self.i: 44假人被摧毁Dummy.__del__(), self.i: 43假人被摧毁Dummy.__del__(), self.i: 42假人被摧毁Dummy.__del__(), self.i: 41假人被摧毁Dummy.__del__(), self.i: 40假人被摧毁Dummy.__del__(), self.i: 39假人被摧毁Dummy.__del__(), self.i: 38假人被摧毁Dummy.__del__(), self.i: 37假人被摧毁Dummy.__del__(), self.i: 36假人被摧毁Dummy.__del__(), self.i: 35假人被摧毁Dummy.__del__(), self.i: 34假人被摧毁Dummy.__del__(), self.i: 33假人被摧毁Dummy.__del__(), self.i: 32假人被摧毁Dummy.__del__(), self.i: 31假人被摧毁Dummy.__del__(), self.i: 30假人被摧毁Dummy.__del__(), self.i: 29假人被摧毁Dummy.__del__(), self.i: 28假人被摧毁Dummy.__del__(), self.i: 27假人被摧毁Dummy.__del__(), self.i: 26假人被摧毁Dummy.__del__(), self.i: 25假人被摧毁Dummy.__del__(), self.i: 24假人被摧毁Dummy.__del__(), self.i: 23假人被摧毁Dummy.__del__(), self.i: 22假人被摧毁Dummy.__del__(), self.i: 21假人被摧毁Dummy.__del__(), self.i: 20假人被摧毁Dummy.__del__(), self.i: 19假人被摧毁Dummy.__del__(), self.i: 18假人被摧毁Dummy.__del__(), self.i: 17假人被摧毁Dummy.__del__(), self.i: 16假人被摧毁Dummy.__del__(), self.i: 15假人被摧毁Dummy.__del__(), self.i: 14假人被摧毁Dummy.__del__(), self.i: 13假人被摧毁Dummy.__del__(), self.i: 12假人被摧毁Dummy.__del__(), self.i: 11假人被摧毁Dummy.__del__(), self.i: 10假人被摧毁Dummy.__del__(), self.i: 9假人被摧毁Dummy.__del__(), self.i: 8假人被摧毁Dummy.__del__(), self.i: 7假人被摧毁Dummy.__del__(), self.i: 6假人被摧毁Dummy.__del__(), self.i: 5假人被摧毁Dummy.__del__(), self.i: 4假人被摧毁Dummy.__del__(), self.i: 3假人被摧毁Dummy.__del__(), self.i: 2假人被摧毁Dummy.__del__(), self.i: 1假人被摧毁Dummy.__del__(), self.i: 0假人被摧毁

What is the correct way to call a Python function from QML that will instantiate and return an object to QML, and have QML side be responsible for the lifetime of the object? The problem I'm facing is that object gets garbage collected before it even reaches QML.

Note that I don't want to keep explicit references to the object on the Python side, and according to the following quote from the documentation what I'm looking for should even be the default behavior:

When data is transferred from C++ to QML, the ownership of the data always remains with C++. The exception to this rule is when a QObject is returned from an explicit C++ method call: in this case, the QML engine assumes ownership of the object...

I have created a minimal runnable example that demonstrates the problem (gist link):

main.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import signal
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQuick import QQuickView
from PyQt5.QtCore import QUrl, QObject, QVariant, pyqtSlot
from PyQt5.QtQml import QQmlEngine, qmlRegisterType


class Dummy(QObject):

    def __del__(self):
        print("Deleted")


class GUIEntryPoint(QObject):

    @pyqtSlot(result=QVariant)
    def get_foo(self):
        foo = Dummy()
        print("Created {}".format(foo))
        print("Ownership after instantiation: {}".format(QQmlEngine.objectOwnership(foo)))
        #QQmlEngine.setObjectOwnership(foo, 1)  # has no effect
        return foo

    @pyqtSlot(QVariant)
    def print_foo(self, foo):
        print("{}, ownership: {}".format(foo, QQmlEngine.objectOwnership(foo)))


def run():
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    app = QGuiApplication(sys.argv)

    # these don't seem to make a difference
    qmlRegisterType(GUIEntryPoint, 'GUIEntryPoint', 1, 0, 'GUIEntryPoint')
    qmlRegisterType(Dummy, 'Dummy', 1, 0, 'Dummy')

    qml_url = QUrl.fromLocalFile(os.path.join('zzz.qml'))
    view = QQuickView()

    gep = GUIEntryPoint()
    view.rootContext().setContextProperty('BE', gep)
    view.setSource(qml_url)

    view.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    run()

zzz.qml:

import QtQuick 2.2


Rectangle {
    id: rootItem
    width: 640
    height: 400

    property var pleaseKeepMe: BE.get_foo()

    Component.onCompleted: {
        console.log("Completed");

        BE.print_foo(pleaseKeepMe);  // prints None, it has been deleted

        console.log("creating another");
        var x = BE.get_foo();
        // at this point x has already been deleted on the Python side
        console.log("created another");
        BE.print_foo(x);  // prints None

        console.log("\n\nPress CTRL-C to exit");
    }
}

解决方案

In short: using SIP Python API to transfer ownership to C++ while keeping the Python "part" of a QObject alive seemingly solves the issue, which is indeed an ownership one, as covered at (also see the comments in sources below):

On SIP API, see:

Also, some nice general advice is at:

A slightly modified example from the question, Python source:

from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQuick import QQuickView
from PyQt5.QtCore import QUrl, QObject, QVariant, pyqtSlot
from PyQt5.QtQml import QQmlEngine, qmlRegisterType
import sip

def ownership(obj):
    jsOwned = QQmlEngine.objectOwnership(obj) == QQmlEngine.JavaScriptOwnership
    return "Javascript" if jsOwned else "Cpp"  

def onDummytDestroyed():
    print "Dummy destroyed"

class Dummy(QObject):

    i = 0

    def __init__(self):
        #let's not forget to properly initialize the base part
        super(Dummy, self).__init__()
        self.i = Dummy.i
        Dummy.i = Dummy.i + 1

    def __del__(self):
        #let's track when the Python part gets destroyed 
        #  (or, rather, "finalized", or whatever the correct term is :) )
        print "Dummy.__del__(), self.i:", self.i

    @pyqtSlot(result="QString")
    def get_str(self):
        #let's have a Python (not C++) implemented method in the class
        return "Dummy string #" + str(self.i)

class GUIEntryPoint(QObject):

    def __init__(self):
        #same as with Dummy.__init__
        super(GUIEntryPoint, self).__init__()

    @pyqtSlot(result=QVariant) #would also work
    #@pyqtSlot(result=QObject)
    def get_foo(self):
        print "GUIEntryPoint.get_foo():"
        foo = Dummy()
        foo.setObjectName("Foo")

        #let's track when the C++ part gets destroyed
        foo.destroyed.connect(onDummytDestroyed)

        #this would destroy the Python part of foo as soon as the reference
        #goes out of scope (the C++ part stay alive and will be properly accessible from QML,
        #but attempts to access Python-implemented methods like Dummy.get_str()
        #would cause a TypeError hinting that there is no such method) 
        #sip.transferto(foo, None)

        #this works as expected, with both Python (and then C++) parts of foo
        #being destroyed whenever the QML GC decides to get rid of the object
        #(see program output, notice how GC is silent for a while)  
        sip.transferto(foo, foo)

        #this is indeed not needed, as proper ownership will be set
        #when the object passes to the QML land through the slot invocation
        #QQmlEngine.setObjectOwnership(foo, QQmlEngine.JavaScriptOwnership)
        print "    initial ownership: ", ownership(foo)

        return foo

    @pyqtSlot(QObject) #would also work
    #@pyqtSlot(QVariant) 
    def print_foo(self, foo):
        print "GUIEntryPoint.print_foo():"
        print "    objectName: ", foo.objectName()
        print "    ownership when on QML side: ", ownership(foo)

app = QGuiApplication([])
view = QQuickView()

#not needed, indeed, as both context objects (and properties),
#and QObject descendants passed to QML side are perfectly accessible
#(that is, their properties and invokables / slots are) 
#without any additional steps
#(instantiating types declaratively would require registering them first, though,
#and having properties of custom types requires metatypes to be declared)
#qmlRegisterType(GUIEntryPoint, 'GUIEntryPoint', 1, 0, 'GUIEntryPoint')
#qmlRegisterType(Dummy, 'Dummy', 1, 0, 'Dummy')

gep = GUIEntryPoint()
view.rootContext().setContextProperty('BE', gep)

view.setSource(QUrl.fromLocalFile("pyqt-ownership-test.qml"))
view.show()

app.exec_()

QML source (save as pyqt-ownership-test.py):

import QtQuick 2.1

Rectangle {
    width: 300
    height: 200
    color: "red"
    border.width: 10

    Component.onCompleted: {
        console.log("Component.onCompleted():")

        //increase the number to 1000 to see GC stepping in
        //while the loop is still running
        //(notice how destruction is not being reported for some objects,
        //for example, #249 (the one created last),
        //but this looks like a Qt/QML logging issue)
        for (var i = 0; i < 250; i++) {
            console.log("#" + i)
            var foo = BE.get_foo()

            console.log("    foo: " + foo)
            console.log("    foo.objectName: " + foo.objectName)
            console.log("    foo.get_str(): " + foo.get_str())

            console.log("    print_foo():")
            BE.print_foo(foo)
        }
    }
}

Program output (stripped in the middle to accomodate SO answer size limit):

Component.onCompleted():
#0
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x22903d0, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #0
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#1
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x2290d20, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #1
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#2
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x2291080, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #2
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#3
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x22911e0, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #3
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#4
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x2291e90, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #4
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#5
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x2292b70, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #5
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#6
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x2293420, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #6
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#7
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x2296e30, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #7
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#8
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x22983b0, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #8
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#9
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x2299150, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #9
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#10
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x2299e60, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #10
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#11
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x229ab70, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #11
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript

<...some lines skipped here...>

#245
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x23007b0, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #245
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#246
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x22fe4d0, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #246
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#247
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x22fc5c0, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #247
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#248
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x22fa730, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #248
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
#249
GUIEntryPoint.get_foo():
    initial ownership:  Cpp
    foo: Dummy(0x22f57b0, "Foo")
    foo.objectName: Foo
    foo.get_str(): Dummy string #249
    print_foo():
GUIEntryPoint.print_foo():
    objectName:  Foo
    ownership when on QML side:  Javascript
Dummy.__del__(), self.i: 214
Dummy destroyed
Dummy.__del__(), self.i: 213
Dummy destroyed
Dummy.__del__(), self.i: 212
Dummy destroyed
Dummy.__del__(), self.i: 211
Dummy destroyed
Dummy.__del__(), self.i: 210
Dummy destroyed
Dummy.__del__(), self.i: 209
Dummy destroyed
Dummy.__del__(), self.i: 208
Dummy destroyed
Dummy.__del__(), self.i: 207
Dummy destroyed
Dummy.__del__(), self.i: 206
Dummy destroyed
Dummy.__del__(), self.i: 205
Dummy destroyed
Dummy.__del__(), self.i: 204
Dummy destroyed
Dummy.__del__(), self.i: 203
Dummy destroyed
Dummy.__del__(), self.i: 202
Dummy destroyed
Dummy.__del__(), self.i: 201
Dummy destroyed
Dummy.__del__(), self.i: 200
Dummy destroyed
Dummy.__del__(), self.i: 199
Dummy destroyed
Dummy.__del__(), self.i: 198
Dummy destroyed
Dummy.__del__(), self.i: 197
Dummy destroyed
Dummy.__del__(), self.i: 196
Dummy destroyed
Dummy.__del__(), self.i: 195
Dummy destroyed
Dummy.__del__(), self.i: 194
Dummy destroyed
Dummy.__del__(), self.i: 193
Dummy destroyed
Dummy.__del__(), self.i: 192
Dummy destroyed
Dummy.__del__(), self.i: 191
Dummy destroyed
Dummy.__del__(), self.i: 190
Dummy destroyed
Dummy.__del__(), self.i: 189
Dummy destroyed
Dummy.__del__(), self.i: 188
Dummy destroyed
Dummy.__del__(), self.i: 187
Dummy destroyed
Dummy.__del__(), self.i: 186
Dummy destroyed
Dummy.__del__(), self.i: 185
Dummy destroyed
Dummy.__del__(), self.i: 184
Dummy destroyed
Dummy.__del__(), self.i: 183
Dummy destroyed
Dummy.__del__(), self.i: 182
Dummy destroyed
Dummy.__del__(), self.i: 181
Dummy destroyed
Dummy.__del__(), self.i: 180
Dummy destroyed
Dummy.__del__(), self.i: 179
Dummy destroyed
Dummy.__del__(), self.i: 178
Dummy destroyed
Dummy.__del__(), self.i: 177
Dummy destroyed
Dummy.__del__(), self.i: 176
Dummy destroyed
Dummy.__del__(), self.i: 175
Dummy destroyed
Dummy.__del__(), self.i: 174
Dummy destroyed
Dummy.__del__(), self.i: 173
Dummy destroyed
Dummy.__del__(), self.i: 172
Dummy destroyed
Dummy.__del__(), self.i: 171
Dummy destroyed
Dummy.__del__(), self.i: 170
Dummy destroyed
Dummy.__del__(), self.i: 169
Dummy destroyed
Dummy.__del__(), self.i: 168
Dummy destroyed
Dummy.__del__(), self.i: 167
Dummy destroyed
Dummy.__del__(), self.i: 166
Dummy destroyed
Dummy.__del__(), self.i: 165
Dummy destroyed
Dummy.__del__(), self.i: 164
Dummy destroyed
Dummy.__del__(), self.i: 163
Dummy destroyed
Dummy.__del__(), self.i: 162
Dummy destroyed
Dummy.__del__(), self.i: 161
Dummy destroyed
Dummy.__del__(), self.i: 160
Dummy destroyed
Dummy.__del__(), self.i: 159
Dummy destroyed
Dummy.__del__(), self.i: 158
Dummy destroyed
Dummy.__del__(), self.i: 157
Dummy destroyed
Dummy.__del__(), self.i: 156
Dummy destroyed
Dummy.__del__(), self.i: 155
Dummy destroyed
Dummy.__del__(), self.i: 154
Dummy destroyed
Dummy.__del__(), self.i: 153
Dummy destroyed
Dummy.__del__(), self.i: 152
Dummy destroyed
Dummy.__del__(), self.i: 151
Dummy destroyed
Dummy.__del__(), self.i: 150
Dummy destroyed
Dummy.__del__(), self.i: 149
Dummy destroyed
Dummy.__del__(), self.i: 148
Dummy destroyed
Dummy.__del__(), self.i: 147
Dummy destroyed
Dummy.__del__(), self.i: 146
Dummy destroyed
Dummy.__del__(), self.i: 145
Dummy destroyed
Dummy.__del__(), self.i: 144
Dummy destroyed
Dummy.__del__(), self.i: 143
Dummy destroyed
Dummy.__del__(), self.i: 142
Dummy destroyed
Dummy.__del__(), self.i: 141
Dummy destroyed
Dummy.__del__(), self.i: 140
Dummy destroyed
Dummy.__del__(), self.i: 139
Dummy destroyed
Dummy.__del__(), self.i: 138
Dummy destroyed
Dummy.__del__(), self.i: 137
Dummy destroyed
Dummy.__del__(), self.i: 136
Dummy destroyed
Dummy.__del__(), self.i: 135
Dummy destroyed
Dummy.__del__(), self.i: 134
Dummy destroyed
Dummy.__del__(), self.i: 133
Dummy destroyed
Dummy.__del__(), self.i: 132
Dummy destroyed
Dummy.__del__(), self.i: 131
Dummy destroyed
Dummy.__del__(), self.i: 130
Dummy destroyed
Dummy.__del__(), self.i: 129
Dummy destroyed
Dummy.__del__(), self.i: 128
Dummy destroyed
Dummy.__del__(), self.i: 127
Dummy destroyed
Dummy.__del__(), self.i: 126
Dummy destroyed
Dummy.__del__(), self.i: 125
Dummy destroyed
Dummy.__del__(), self.i: 124
Dummy destroyed
Dummy.__del__(), self.i: 123
Dummy destroyed
Dummy.__del__(), self.i: 122
Dummy destroyed
Dummy.__del__(), self.i: 121
Dummy destroyed
Dummy.__del__(), self.i: 120
Dummy destroyed
Dummy.__del__(), self.i: 119
Dummy destroyed
Dummy.__del__(), self.i: 118
Dummy destroyed
Dummy.__del__(), self.i: 117
Dummy destroyed
Dummy.__del__(), self.i: 116
Dummy destroyed
Dummy.__del__(), self.i: 115
Dummy destroyed
Dummy.__del__(), self.i: 114
Dummy destroyed
Dummy.__del__(), self.i: 113
Dummy destroyed
Dummy.__del__(), self.i: 112
Dummy destroyed
Dummy.__del__(), self.i: 111
Dummy destroyed
Dummy.__del__(), self.i: 110
Dummy destroyed
Dummy.__del__(), self.i: 109
Dummy destroyed
Dummy.__del__(), self.i: 108
Dummy destroyed
Dummy.__del__(), self.i: 107
Dummy destroyed
Dummy.__del__(), self.i: 106
Dummy destroyed
Dummy.__del__(), self.i: 105
Dummy destroyed
Dummy.__del__(), self.i: 104
Dummy destroyed
Dummy.__del__(), self.i: 103
Dummy destroyed
Dummy.__del__(), self.i: 102
Dummy destroyed
Dummy.__del__(), self.i: 101
Dummy destroyed
Dummy.__del__(), self.i: 100
Dummy destroyed
Dummy.__del__(), self.i: 99
Dummy destroyed
Dummy.__del__(), self.i: 98
Dummy destroyed
Dummy.__del__(), self.i: 97
Dummy destroyed
Dummy.__del__(), self.i: 96
Dummy destroyed
Dummy.__del__(), self.i: 95
Dummy destroyed
Dummy.__del__(), self.i: 94
Dummy destroyed
Dummy.__del__(), self.i: 93
Dummy destroyed
Dummy.__del__(), self.i: 92
Dummy destroyed
Dummy.__del__(), self.i: 91
Dummy destroyed
Dummy.__del__(), self.i: 90
Dummy destroyed
Dummy.__del__(), self.i: 89
Dummy destroyed
Dummy.__del__(), self.i: 88
Dummy destroyed
Dummy.__del__(), self.i: 87
Dummy destroyed
Dummy.__del__(), self.i: 86
Dummy destroyed
Dummy.__del__(), self.i: 85
Dummy destroyed
Dummy.__del__(), self.i: 84
Dummy destroyed
Dummy.__del__(), self.i: 83
Dummy destroyed
Dummy.__del__(), self.i: 82
Dummy destroyed
Dummy.__del__(), self.i: 81
Dummy destroyed
Dummy.__del__(), self.i: 80
Dummy destroyed
Dummy.__del__(), self.i: 79
Dummy destroyed
Dummy.__del__(), self.i: 78
Dummy destroyed
Dummy.__del__(), self.i: 77
Dummy destroyed
Dummy.__del__(), self.i: 76
Dummy destroyed
Dummy.__del__(), self.i: 75
Dummy destroyed
Dummy.__del__(), self.i: 74
Dummy destroyed
Dummy.__del__(), self.i: 73
Dummy destroyed
Dummy.__del__(), self.i: 72
Dummy destroyed
Dummy.__del__(), self.i: 71
Dummy destroyed
Dummy.__del__(), self.i: 70
Dummy destroyed
Dummy.__del__(), self.i: 69
Dummy destroyed
Dummy.__del__(), self.i: 68
Dummy destroyed
Dummy.__del__(), self.i: 67
Dummy destroyed
Dummy.__del__(), self.i: 66
Dummy destroyed
Dummy.__del__(), self.i: 65
Dummy destroyed
Dummy.__del__(), self.i: 64
Dummy destroyed
Dummy.__del__(), self.i: 63
Dummy destroyed
Dummy.__del__(), self.i: 62
Dummy destroyed
Dummy.__del__(), self.i: 61
Dummy destroyed
Dummy.__del__(), self.i: 60
Dummy destroyed
Dummy.__del__(), self.i: 59
Dummy destroyed
Dummy.__del__(), self.i: 58
Dummy destroyed
Dummy.__del__(), self.i: 57
Dummy destroyed
Dummy.__del__(), self.i: 56
Dummy destroyed
Dummy.__del__(), self.i: 55
Dummy destroyed
Dummy.__del__(), self.i: 54
Dummy destroyed
Dummy.__del__(), self.i: 53
Dummy destroyed
Dummy.__del__(), self.i: 52
Dummy destroyed
Dummy.__del__(), self.i: 51
Dummy destroyed
Dummy.__del__(), self.i: 50
Dummy destroyed
Dummy.__del__(), self.i: 49
Dummy destroyed
Dummy.__del__(), self.i: 48
Dummy destroyed
Dummy.__del__(), self.i: 47
Dummy destroyed
Dummy.__del__(), self.i: 46
Dummy destroyed
Dummy.__del__(), self.i: 45
Dummy destroyed
Dummy.__del__(), self.i: 44
Dummy destroyed
Dummy.__del__(), self.i: 43
Dummy destroyed
Dummy.__del__(), self.i: 42
Dummy destroyed
Dummy.__del__(), self.i: 41
Dummy destroyed
Dummy.__del__(), self.i: 40
Dummy destroyed
Dummy.__del__(), self.i: 39
Dummy destroyed
Dummy.__del__(), self.i: 38
Dummy destroyed
Dummy.__del__(), self.i: 37
Dummy destroyed
Dummy.__del__(), self.i: 36
Dummy destroyed
Dummy.__del__(), self.i: 35
Dummy destroyed
Dummy.__del__(), self.i: 34
Dummy destroyed
Dummy.__del__(), self.i: 33
Dummy destroyed
Dummy.__del__(), self.i: 32
Dummy destroyed
Dummy.__del__(), self.i: 31
Dummy destroyed
Dummy.__del__(), self.i: 30
Dummy destroyed
Dummy.__del__(), self.i: 29
Dummy destroyed
Dummy.__del__(), self.i: 28
Dummy destroyed
Dummy.__del__(), self.i: 27
Dummy destroyed
Dummy.__del__(), self.i: 26
Dummy destroyed
Dummy.__del__(), self.i: 25
Dummy destroyed
Dummy.__del__(), self.i: 24
Dummy destroyed
Dummy.__del__(), self.i: 23
Dummy destroyed
Dummy.__del__(), self.i: 22
Dummy destroyed
Dummy.__del__(), self.i: 21
Dummy destroyed
Dummy.__del__(), self.i: 20
Dummy destroyed
Dummy.__del__(), self.i: 19
Dummy destroyed
Dummy.__del__(), self.i: 18
Dummy destroyed
Dummy.__del__(), self.i: 17
Dummy destroyed
Dummy.__del__(), self.i: 16
Dummy destroyed
Dummy.__del__(), self.i: 15
Dummy destroyed
Dummy.__del__(), self.i: 14
Dummy destroyed
Dummy.__del__(), self.i: 13
Dummy destroyed
Dummy.__del__(), self.i: 12
Dummy destroyed
Dummy.__del__(), self.i: 11
Dummy destroyed
Dummy.__del__(), self.i: 10
Dummy destroyed
Dummy.__del__(), self.i: 9
Dummy destroyed
Dummy.__del__(), self.i: 8
Dummy destroyed
Dummy.__del__(), self.i: 7
Dummy destroyed
Dummy.__del__(), self.i: 6
Dummy destroyed
Dummy.__del__(), self.i: 5
Dummy destroyed
Dummy.__del__(), self.i: 4
Dummy destroyed
Dummy.__del__(), self.i: 3
Dummy destroyed
Dummy.__del__(), self.i: 2
Dummy destroyed
Dummy.__del__(), self.i: 1
Dummy destroyed
Dummy.__del__(), self.i: 0
Dummy destroyed

这篇关于QML 不拥有从 PyQt 插槽接收的对象的所有权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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