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. QML Loader: item.property binding is set only during loading, but is not linked
Forum Updated to NodeBB v4.3 + New Features

QML Loader: item.property binding is set only during loading, but is not linked

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 10.2k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    bkamps
    wrote on 4 Jun 2012, 06:50 last edited by
    #1

    Hi,

    I have the following loader:

    @
    Loader {
    source: "myWindow.qml"
    onLoaded: { item.title= myCppObject.title }
    }
    @
    When myWindow is loaded the title is set, but when I change the title using myCppObject the title is not changed!

    @
    class MyCppObject : public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QString title READ Title NOTIFY TitleChanged)

    public:
    MyCppObject (QObject* aParent = 0);
    virtual ~MyCppObject ();

             void SetTitle(const QString & aTitle);
    

    public slots:
    const QString & Title();

    signals:

             void TitleChanged();
    

    private:
    QString mTitle;
    };
    @

    @
    void MyCppObject::SetTitle(const QString & aTitle)
    {
    mTitle = aTitle;
    emit TitleChanged();
    }

    const QString & MyCppObject::Title()
    {
    return Title;
    }
    @

    Before I haven't used the loader but just created all my windows at once during startup of my application. When I emitted a signal from c++ the QML object was notified and updated. When I use the loader and the onLoaded/item. construction the QML object isn't notified anymore when a change occurs.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bkamps
      wrote on 4 Jun 2012, 12:41 last edited by
      #2

      Found the answer. Use Binding:

      @
      Binding {
      target: loader.item
      property: "model"
      value: model
      when: loader.status == Loader.Ready
      }
      @

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chriadam
        wrote on 6 Jun 2012, 23:27 last edited by
        #3

        Yes, the assignment form in your first post won't cause a binding. In QtQuick 1.x you can use a Binding element, and in QtQuick 2.0 you can either use a Binding element, or use the "initial property values" argument to the setSource function of the Loader, along with the Qt.binding() function, to generate a binding.

        1 Reply Last reply
        0

        1/3

        4 Jun 2012, 06:50

        • Login

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