[英]Remove dynamic properties from QObject
有没有办法删除分配给QObject
所有动态属性?
Try this: 尝试这个:
for (auto const &name : object->dynamicPropertyNames())
{
object->setProperty(name.constData(), {});
}
Q_ASSERT(object->dynamicPropertyNames().empty());
This iterates over all dynamic properties and sets empty QVariant
value. 这将迭代所有动态属性并设置空的
QVariant
值。 If assertion fails than this is a Qt bug since documetation says: 如果断言失败,那么这是一个Qt错误,因为文档说:
http://doc.qt.io/qt-5/qobject.html#dynamic-properties http://doc.qt.io/qt-5/qobject.html#dynamic-properties
From Qt 4.2, dynamic properties can be added to and removed from QObject instances at run-time.
从Qt 4.2开始,可以在运行时向QObject实例添加和删除动态属性。
and 和
Dynamic properties ... can be removed by setting the property value to an invalid
QVariant
.可以通过将属性值设置为无效的
QVariant
来删除动态属性....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.