Results 1 to 8 of 8

Thread: QQmlPropertyMap, model

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    2
    Platforms
    Unix/X11 Windows

    Default Re: QQmlPropertyMap, model

    Quote Originally Posted by wysota View Post
    Bind the object's property to a function call that will return the data or invoke some imperative code when contents of the model change.
    This is fine, I have the QML object's property bound to the a function (I can see it hitting the breakpoint where I return a value) however, this only gets called once while the QML object is loading. From that point on, it never updates despite the data changing (this the issue QQmlPropertyMap and the likes resolved). I guess the question then boils down to, how can I update the QML object when I know data that it references has been updated?

    Edit: I've had a bit of a play with this and the only solution I can come up with is binding the QML object's value a C++ object's property and provide a NOTIFY signal
    Qt Code:
    1. C++:
    2. class Runtime : public QObject
    3. {
    4. Q_OBJECT
    5. Q_PROPERTY(RuntimeData* data READ GetData NOTIFY modelChanged)
    6. public:
    To copy to clipboard, switch view to plain text mode 

    The RuntimeData object is my QAbstractListModel derived object. In this object I've then created a Q_INVOKABLE member that retuns the data value base on an index (for now).
    Qt Code:
    1. class RuntimeData : public QAbstractListModel
    2. {
    3. Q_OBJECT
    4. public:
    5. Q_INVOKABLE int GetData(int index)
    6. {
    7. if (index >= 0 && index < m_Data.count())
    8. return m_Data[index].Value().toInt();
    9. return 0;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Finally, its all working but there is a remaining issue. With this implementaion, anytime I have to update any data, I also have to emit the modelChanged signal to inform the QML to update. Hypothetically if I have 1000 data entries and 1000 QML objects bound to these, if one data item changes all QML objects will update.

    Again, I feel like I must be missing something? Why is this so complicated?
    Last edited by sBoff; 27th August 2013 at 11:04.

Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 19:39
  2. Replies: 0
    Last Post: 2nd November 2011, 11:13
  3. Event handlers for QTableView model / selection model.
    By hickscorp in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2011, 17:57
  4. Using model indices in complex model item relationships
    By hackerNovitiate in forum Newbie
    Replies: 0
    Last Post: 29th June 2011, 14:30
  5. Model/view, apply a filter on model
    By remy_david in forum Qt Programming
    Replies: 4
    Last Post: 4th February 2011, 17:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.