QQmlListProperty constructor doesn't accept my arguments
-
Hi,
I'm doing my first steps with QQmlListProperty.
Unfortunately I'm not able to create such list :-(header:
class TestClass : public QQuickFramebufferObject { Q_OBJECT Q_PROPERTY(QQmlListProperty<TestItem> lstTestItems READ lstTestItems) private: static int count_lstTestItems(QQmlListProperty<TestItem> *list); static TestItem* at_lstTestItems(QQmlListProperty<TestItem> *list, int index); public: QQmlListProperty<TestItem> lstTestItems() const; }
source:
QQmlListProperty<TestItem> TestClass::lstTestItems() const { return QQmlListProperty<TestItem>(this, 0, &TestClass::count_lstTestItems, &TestClass::at_lstTestItems); }
Error:
error: C2665: "QQmlListProperty<TestItem>::QQmlListProperty": Durch keine der 5 Überladungen konnten alle Argumenttypen konvertiert werden.What am I missing here?
Thanks!
mtsP.S. how can I mark parts of my post as code?
[edit: Added missing coding tags three back sticks to start and three to end SGaist]
-
OK, i did nearly the same as you here an working example.
// declare Q_PROPERTY(QQmlListProperty<QObject> fields READ fields) //getter QQmlListProperty<QObject> fields(); //member to fill with data QList<QObject*> m_fields; //implementation of the getter QQmlListProperty<Object> YourClass::fields() { return QQmlListProperty<Object>(this, this->m_fields); }
Thats all for me. I have to replace MyCustomClass with QObject but my custom class derived from QObject this is needed see documentation of QQmlListProperty
[edit: updated coding tags SGaist]
-
Hmm,
my biggest misstake was my CustomClass have a namespace so if you use namespace also u need to do this:
Q_PROPERTY(QQmlListPropertyfull::namespace::CustomClass fields READ fields)
-
No i dont want to say u need to replace your custom class with QObject sorry my english is horrible. I did this for this example because in my production code i have to use my custom class so this doesn't make sense here to post.
Not enough info to help you, i doesn't know how your TestItem class looks like
-
TestItemClass:
class TestItem : public NChartRenderItem { Q_OBJECT private: QOpenGLBuffer *m_vertexBuffer = NULL; public: TestItem(); ~TestItem(); // NChartRenderItem interface public: bool createVertexBuffer(int bufferSize); bool renderItem(); };
NChartRenderItem-Class:
class NChartRenderItem : public QObject { Q_OBJECT public: explicit NChartRenderItem(QObject *parent = 0); ~NChartRenderItem(); virtual bool createVertexBuffer(int bufferSize) = 0; virtual bool renderItem() = 0; signals: public slots: };
-
Hmm can u show me the constructor implementation?
-
@themts said:
QQmlListProperty<TestItem> TestClass::lstTestItems() const
{
return QQmlListProperty<TestItem>(this, 0, &TestClass::count_lstTestItems, &TestClass::at_lstTestItems);
}Why this?
In my impelentation it looks diffrent.
<pre><code>
//implementation of the getter
QQmlListProperty<Object> YourClass::fields() {
return QQmlListProperty<Object>(this, this->m_fields);
}
</code></pre> -
QQmlListProperty has 3 constructor. I'm using this one:
http://doc.qt.io/qt-5/qqmllistproperty.html#QQmlListProperty-4That way I can use it as a "virtual" list.
Anyway, even if I use it your way - which is not recommended - it shows the same error.
"Generally this constructor should not be used in production code, as a writable QList violates QML's memory management rules. However, this constructor can be very useful while prototyping."QList<TestItem*> m_lstTestItems;
return QQmlListProperty<TestItem>(this, this->m_lstTestItems);
-
OK, thanks for your hints. I will definitely change this. I saw this in different sample codes. But my c++ and QT knowledge is very nooby :) Sorry that i can't help u. Not really an idea.
-
Can u show me the constructor implementation of your NChartRenderItem class?
-
I really don't understand why it's not working.
I even tried to use Q_PROPERTY(QQmlListProperty<QObject> ... -> same resultI don't get it. The error-message (C2665) seems to be wrong as well: it says 5 overloads.
Actually there are only 4.Does anyone has an idea?
Btw. I want to use QQmlListProperty as a datamodel for a listview.