Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]binding from C++: value can not updated automatically
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    unixmania
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • U Offline
        U Offline
        unixmania
        wrote on last edited by
        #3

        not. am i have to do it?

        1 Reply Last reply
        0
        • U Offline
          U Offline
          unixmania
          wrote on last edited by
          #4

          yes .thanks.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rolias
            wrote on last edited by
            #5

            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.

            Check out my third course in the trilogy on Qt
            "Integrating Qt Quick with C++"
            http://bit.ly/qtquickcpp
            published by Pluralsight

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved