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. Passing QAbstractListModel to QML
Qt 6.11 is out! See what's new in the release blog

Passing QAbstractListModel to QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.1k Views
  • 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
    Beemaneni Bala
    wrote on last edited by
    #1

    Hi,
    I have created a c++ class derived from QAbstractListModel and registered (using root context) same with QML to display a data on the ListView. I am able to successfully do that. Usually we do register on main.cpp to let QML know about the class.
    The problem i have is on the model in QML, i need to filter the data on model by its type. So when i start filtering i need to clear the model and fetch data from database and loads back to model again. This is time consuming and at the same time my UI freezes until data is loaded. So i understud as my class is kept on main.cpp it resides on main thread and operation on that class will behave so.

    My implementation is as follows:
    on main.cpp:

    EventStatusModel *eventModel = EventStatusModel::instance();
    viewer.rootContext()->setContextProperty("eventModelObject", eventModel);
    

    on QML:
    ListView{
    model: eventModelObject
    }

    So here on the model when i start filtering , i have created a worker thread which will access EventStatusModel and clear its data and fetches data from tables and loads back to EventStatusModel.

    Hope i have explained situation well. Here i need to know whether i can use any approaches to avoid freeze on UI

    Regards
    Bala B

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mammamia
      wrote on last edited by
      #2

      I have done an example similar to yours with sorting and filtering property.

      My example is described here in this blog

      And the complete source code is available here Git:/QMLSortFilterList

      Hope this helps!

      1 Reply Last reply
      0

      • Login

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