[Solved by workaround] QQmlListProperty, Qt5.1, QtQuick2
-
Hi.
I'm trying to implement a class that uses the QQmlListProperty. I do however get the following compiler error:
error: C2661: 'QQmlListProperty<T>::QQmlListProperty' : no overloaded function takes 3 arguments
with
[
T=ContainerObject
]The ContainerObject works fine i QML (both using qmlRegisterType and setContextProperty(), so it should not be a QObject problem.
I am using this link as reference:
http://qt-project.org/doc/qt-5.1/qtqml/qtqml-cppintegration-exposecppattributes.htmlContainer class implementation:
@#ifndef CONTAINER_H
#define CONTAINER_H#include <QObject>
#include <QQmlListProperty>
#include "containerobject.h"class Container : public QObject
{
private:
//Qt specifics
Q_OBJECT
Q_PROPERTY(QQmlListProperty<ContainerObject> words READ getWords NOTIFY containerChanged)//Properties QList<ContainerObject *>* m_Words; //Functions (QQmlListProperty specific) static void appendWords(QQmlListProperty<ContainerObject> *list, ContainerObject *word);
public:
explicit Container(QObject *parent = 0);
QQmlListProperty<ContainerObject> getWords() const;signals:
void containerChanged();public slots:
};
#endif // CONTAINER_H@
@#include "container.h"
#include <QQmlListProperty>Container ::Container(QObject *parent) :
QObject(parent)
{
m_Words = new QList<ContainerObject *>();
}QQmlListProperty<ContainerObject> Container::getWords() const
{
return QQmlListProperty<ContainerObject>(this, 0, &Container::appendWords);
// return QQmlListProperty<ContainerObject>(this, 0, &Container::appendWords, NULL, NULL, NULL);
}void Container::appendWords(QQmlListProperty<ContainerObject> *list, ContainerObject *word)
{
Container wordList = qobject_cast<Container>(list->object);
if(word)
{
wordList->m_Words->append(word);
}
}
@ -
Hi,
I'm not sure if it will work for you, but removing the const for getWord() may solve your problem.
-
Hi.
I've done a workaround by making a "at(int index)" function which is fine for my solution.
Thanks for your reply.