正如官方文档所述,我试图使用QQmlListProperty将QList传递给QML:
var directory = new DirectoryInfo(DirectoryPath);
var query = directory.GetFiles("*.bmp", SearchOption.AllDirectories);
foreach (var file in query.OrderByDescending(file => file.CreationTime).Skip(1))
{
file.Delete();
}
我的代码是:
QQmlListProperty::QQmlListProperty(QObject *object, void *data, CountFunction count, AtFunction at)
但是我收到了错误:
QQmlListProperty<TTimingDriver> TTiming::getDrivers()
{
return QQmlListProperty<TTimingDriver>(this, &m_drivers, &TTiming::count, &TTiming::driverAt);
}
int TTiming::count(QQmlListProperty<TTimingDriver> *property)
{
TTiming * timing = qobject_cast<TTiming *>(property->object);
return timing->m_drivers.count();
}
TTimingDriver * TTiming::driverAt(QQmlListProperty<TTimingDriver> *property, int i)
{
TTiming * timing = qobject_cast<TTiming *>(property->object);
return timing->m_drivers.at(i);
}
答案 0 :(得分:0)
我想
获取QList的那个不需要指向函数的指针。
所以这应该足够了
QQmlListProperty<TTimingDriver> TTiming::getDrivers()
{
return QQmlListProperty<TTimingDriver>(this, m_drivers);
}
假设m_drivers的类型为QList<TTimingDriver*>