[Interest] QObject-derived default property read-only

Brian Dentino brian.dentino at gmail.com
Mon Oct 13 03:33:41 CEST 2014


I'm working on a qml plugin in which I register a QObject-derived type for use within qml. I've set the default property on this item to be a QQmlListProperty<(other qobject derived type)>, and I've setup a READ function for this property. For some reason the qml engine will not load my application, complaining that this default property is read-only. 

I understand you typically have to define a WRITE function in order to make properties writeable from qml, but the example that comes with Qt regarding default properties does not do this, and it compiles fine:
http://qt-project.org/doc/qt-5/qtqml-referenceexamples-default-example.html

Here's the class definition I'm using:

class DefaultContent : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QQmlListProperty<ShareableItem> attachments READ attachments)
    Q_CLASSINFO("DefaultProperty", "attachments")

public:
    explicit DefaultContent(QObject* parent = 0);

    QQmlListProperty<ShareableItem> attachments();

signals:

public slots:

private:
    QList<ShareableItem*> m_attachments;

};

And the qml...

import QtQuick.2.2
import QtQuick.Window 2.1
import Qtino.SharingKit 1.0 	//This is my plugin that registers 'DefaultContent'

Window {
    DefaultContent {
        id: defaultContentItem
        ImageItem { source: rootScreenGrab.url }
    }
}

The error I get is "Invalid property assignment: "attachments" is a read-only property"

Am I doing something obviously wrong here? If I absolutely must have a WRITE method on this property, how would that work with a QQmlListProperty type if the backing model is a QList? Would the list be owned by js or cpp? And how is that the provided Qt example can work without a WRITE method?

Any help would be much appreciated,
Brian


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20141012/e3f4fe11/attachment.html>


More information about the Interest mailing list