有没有办法删除分配给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. If assertion fails than this is a Qt bug since documetation says:
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.
and
Dynamic properties ... can be removed by setting the property value to an invalid
QVariant
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.