Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED]binding from C++: value can not updated automatically



  • hi.
    i implemented my own Object derived class and embeded it to qml context. Code as

    @
    class my_class : public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QString vlist MEMBER vlist NOTIFY vlistch)
    ...
    public:
    QString vlist;
    ...

    public slots:
    void change_vlist();
    ...
    signals:
    void vlistch();

    ..snip..
    

    QQmlContext* ctx = engine->rootContext();

    my_class fm;

    ctx->setContextProperty("my_class_fm",&fm);

    engine->load(QUrl("main.qml"));

    ..snip..(main.qml)

    Button
    {
    ...
    onClicked:my_class_fm.change_vlist()
    }

    Text
    {
    text:my_class_fm.vlist // value can not automatically updated, why?

    .....
    

    @

    when i changed the value of "vlist" into qml direcly, "text" property automatically updated.

    But i changed vlist internally via called member function which change the value then "text" property

    not updated automatically. i wonder why? is this a threading issue? is there another way to succeed?

    Thanks



  • Did you emit your @vlistch()@ signal when doing the internal change?



  • not. am i have to do it?



  • yes .thanks.



  • I must admit I'm not a big fan of the MEMBER decorator. You might be interested in my AUTO_PROPERTY macro. I wrote up my reasoning and links to the macro code in "this blog post":http://syncor.blogspot.com/2014/11/qt-auto-property.html. In addition to keeping your private implementation details private, it writes the notify signal for you.


Log in to reply