我試圖用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