QQmlListProperty append function called with incomplete object

  • Hello everyone, I'm using a QQmlListProperty to emulate a list of objects in QML:

    class SomeObj : public QObject
    	Q_PROPERTY(QList<qreal> xx READ getX WRITE setX)
    	Q_PROPERTY(QString name READ getName WRITE setName)
    	const QList<qreal>& getX() const;
    	void setX(const QList<qreal>&);
    	// ... rest
    class SomeContainer : public QQuickPaintedItem
            // some properties
    	Q_PROPERTY(QQmlListProperty<SomeObj> objects READ getObjects)
        SomeContainer(QQuickItem* parent = 0);
        static void appendObj(QQmlListProperty<SomeObj> *list, SomeObj *pdt);
        // other functions to support QQmlListProperty 
    // rest...
    // QML
    Item {
    	SomeContainer {
    		objects  : [
    			SomeObj {
    				name : "obj1"
    				xx : [1, 2, 3]			
    			SomeObj {
    				name : "obj2"
    				xx : [10, 20, 30]

    It happens that appendObj is called passing kind of "incomplete" SomeObj*, that is "name" is properly set but xx is not (and setX is called just after appendObj).

    Is there anything to do in order to guarantee that appendObj is called only when a complete SomeObj gets constructed from its arguments declared in the QML? I was expecting this trivial behavior.

    What am I missing?



Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.