QtScript: Q_PROPERTY WRITE function of Prototype not called when object wrapped in QScriptClass

  • Before I log this as a bug, hopefully someone can spot a problem with what I'm doing.

    Do I have the wrong understanding of how QScriptClass and a custom prototype should be used?

    I'm using the QtScript CustomClass example as the code template, where they wrap QByteArray. My code is identical in structure except
    wrapping different objects.

    It seems that the Q_PROPERTY READ function is called when querying a property, but the WRITE function is never called (in the Prototype class)

    In my derived QScriptClass::queryProperty() I am always returning 0 so this means both reads and writes should be delegated to my custom Prototype (QScriptable derived) object.

    This works as expected for property reads, I verify the Prototype object is called i.e:

    a = new Control();

    But when I do:

    a.prop1 = 'ssss';

    the setter function in the Prototype object is not called, but instead it looks like a new property is added to 'a' chain and overrides the prototype, and now print(a.prop1) doesn't go through the Prototype object at all.

    print(a.prop2) is still routed through the Prototype object.

    If I return HandlesWriteAccess in queryProperty(), then setProperty() is called as expected, but I don't want that (or would prefer not too).

    Changing the argument types on setXX makes no difference.
    class ControlAlertPrototype : public QObject, public QScriptable
    Q_PROPERTY(QString title READ title WRITE setTitle)
    Q_PROPERTY(QScriptValue text READ text WRITE setText)
    Q_PROPERTY(QString button1 READ button1 WRITE setButton1)
    Q_PROPERTY(QString button2 READ button2 WRITE setButton2)
    ControlAlertPrototype(QObject *parent = 0);

    BFL::ControlAlert *thisAlert() const;

    QString title() const { return thisAlert()->GetTitle().c_str(); }
    void setTitle(const QString &v) { thisAlert()->SetTitle(v.toStdString().c_str()); }
    QString text() const { return thisAlert()->GetText().c_str(); }
    void setText(const QScriptValue &v) { thisAlert(); /*->SetText(v.toStdString().c_str()); */ }
    QString button1() const { return thisAlert()->GetButton1().c_str(); }
    void setButton1(const QString &v) { thisAlert()->SetButton1(v.toStdString().c_str()); }
    QString button2() const { return thisAlert()->GetButton2().c_str(); }
    void setButton2(const QString &v) { thisAlert()->SetButton2(v.toStdString().c_str()); }

    public slots:
    QString toString() {return "ControlAlert";}

  • Hi Tim;

    Have been solved the problem ? I've the same problem !

  • Hi Tim;

    Have been solved the problem ? I've the same problem !

Log in to reply

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