Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Best way to populate/update/delete info from a list(ListView/ListModel) from C++



  • Hi everyone.
    I'm looking for a best way to populate, update a certain element or delete it from a list(LiswView) from C++
    The list will be updated from multiple threads.

    The best way I found so far is to create a threaded ListModel like this one: "Threaded ListModel Example":http://doc.qt.nokia.com/4.7/declarative-threading-threadedlistmodel.html

    then I will access javascript function from C++ using "QMetaObject::invokeMethod":http://doc.qt.nokia.com/4.7/qml-extending-types.html#adding-new-methods

    Do you think my method is safe in terms of performance because a lot of ListModel elements will be updated in the same time. Also the ListModel will have around 200-300 elements.

    Do you think of a better method to achieve this?

    Also an informative question , how do I send this parameter from c++ using invokeMethod?
    @var msg = {'action': 'appendCurrentTime', 'model': listModel};@



  • Hi,

    If the model is primarily going to be manipulated from C++, you could also consider writing a custom QAbstractListModel subclass (you'll need to handle the threading yourself though)

    Regards,
    Michael


Log in to reply