Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

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

    QML and Qt Quick
    3
    5
    864
    Loading More Posts
    • 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
      unixmania last edited by

      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 Reply Quote 0
      • T
        t3685 last edited by

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

        1 Reply Last reply Reply Quote 0
        • U
          unixmania last edited by

          not. am i have to do it?

          1 Reply Last reply Reply Quote 0
          • U
            unixmania last edited by

            yes .thanks.

            1 Reply Last reply Reply Quote 0
            • R
              Rolias last edited by

              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 Reply Quote 0
              • First post
                Last post