QtObject 有 destroy() 方法吗?
Does QtObject have a destroy() method?
此代码运行无误:
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
QtObject {
id: foo
}
Component.onCompleted: {
foo.destroy()
}
}
但是 QtObject 的文档没有说它有 destroy() 方法。也是吗?
destroy()
方法用于删除dynamically created objects in QML。您示例中的 QtObject
是静态创建的,上面的文档说您不能对此类对象调用 destroy()
:
This would result in an error, since objects can only be dynamically destroyed if they were dynamically created.
我不确定为什么您的示例没有出现错误,但这绝对不是您应该做的事情。
此代码运行无误:
import QtQuick 2.6
import QtQuick.Window 2.2
Window {
visible: true
QtObject {
id: foo
}
Component.onCompleted: {
foo.destroy()
}
}
但是 QtObject 的文档没有说它有 destroy() 方法。也是吗?
destroy()
方法用于删除dynamically created objects in QML。您示例中的 QtObject
是静态创建的,上面的文档说您不能对此类对象调用 destroy()
:
This would result in an error, since objects can only be dynamically destroyed if they were dynamically created.
我不确定为什么您的示例没有出现错误,但这绝对不是您应该做的事情。