我试图用QQmlListProperty从QQuickItem中暴露出的QList - 并在文档以下内容:Qt的编译器错误时尝试使用QQmlListProperty
一个简化的例子:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickItem>
#include <QList>
#include <QQmlListProperty>
class GameEngine : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<QObject> vurms READ vurms)
public:
explicit GameEngine(QQuickItem *parent = 0) :
QQuickItem(parent)
{
}
QQmlListProperty<QObject> vurms() const
{
return QQmlListProperty<QObject>(this, &m_vurms);
}
protected:
QList<QObject*> m_vurms;
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
return app.exec();
}
#include "main.moc"
但我刚开始在return QQmlListProperty<QObject>(this, &m_vurms);
GA编译器错误:
main.cpp:20: error: C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'QQmlListProperty<QObject>'
我也尝试带有int的QList更换Vurm的QList作 - 这个问题似乎是在任何Qt是在做QQmlListProperty<T>(this, &m_vurms);
我写/编译使用Qt 5.8和C++ 11在.pro文件中设置。我正在编译Windows 10上的Qt Creator 4.2.1:使用MSVC 2015 64位进行编译。
尝试从功能删除了'const'预选赛。 – Mitch
@米奇 - 不使用时限定在误差保持甚至,当我阅读文档时,常量需要在那里... – HorusKol
我不知道发生了什么事的文档......这是常量的声明,但不在定义中。也许问题是'Vurm' - 你能提供头文件吗? – Mitch