Results 1 to 7 of 7

Thread: QAbstractListModel does not update QML ListView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QAbstractListModel does not update QML ListView

    Hi wysota,

    Thank you, that helps clarify things. You recommended I "connect to the model's event." What event would that be? Would you recommend instead that I add Q_PROPERTYs to the _arrivingVisitorModel class that are always connected to the property of the current model index? In other words, something like

    Qt Code:
    1. // visitormodel.h
    2. class VisitorModel : public QAbstractListModel
    3. {
    4. Q_OBJECT
    5. Q_PROPERTY(QString m_vin READ vin WRITE setVin NOTIFY vinChanged)
    6. // ...
    7. void setVin(const QString& vin);
    8. QString vin() const;
    9. // ...
    10. signals:
    11. void vinChanged(QString vin);
    12. // ...
    13. private:
    14. QList<VehicleItem*> m_list;
    15. };
    16.  
    17. // visitormodel.cpp
    18. QString VisitorModel::vin() const
    19. {
    20. return m_list[currentIndex].vin();
    21. }
    22.  
    23. void VisitorModel::setVin(const QString& vin)
    24. {
    25. if(m_list[currentIndex].vin() != vin)
    26. {
    27. m_list[currentIndex].setVin(vin);
    28. emit vinChanged();
    29. emit dataChanged();
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    In general, what is the recommended approach for communicating individual property/data member changes of each item in a QAbstractListModel-derived model to QML?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractListModel does not update QML ListView

    The model has a bunch of signals (such as dataChanged, rowsInserted, etc.) you can connect to. No need to create new signals. Also bear in mind the model has no concept of a "current index". A model is just an interface to data, it has no notion of a "current" index. That's an attribute of the view.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QAbstractListModel does not update QML ListView

    Thanks wysota. I'll try connecting to the dataChanged signal.

Similar Threads

  1. Replies: 1
    Last Post: 20th October 2011, 10:08
  2. ListView model binding to QAbstractListModel
    By michalk in forum Qt Quick
    Replies: 1
    Last Post: 16th July 2011, 09:21
  3. QAbstractListModel
    By Archa4 in forum Newbie
    Replies: 9
    Last Post: 9th February 2011, 14:43
  4. Problem with QAbstractListModel
    By eekhoorn12 in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2009, 14:26
  5. QAbstractListModel searching.
    By ComaWhite in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2009, 18:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.