QQmlListProperty constructor doesn't accept my arguments
-
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.