Generate a C++ Qt desktop application boilerplate with the Model-View-Delegate pattern. Fetch data from a REST API in a background QThread, update a custom QAbstractListModel, and render in QML without freezing the GUI.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Providing boilerplate Qt Model-View-Delegate example
I'll write minimal C++ classes for the worker (using QNetworkAccessManager in its own QThread with its event loop), the ListModel, and main.cpp wiring everything together, plus a QML file binding a ListView to the model via context property, demonstrating a background REST fetch updating the UI without freezing.
Below is a minimal, but complete example of a Qt 6+ (works similarly with Qt 5) desktop application using a QAbstractListModel (Model), a QML ListView (View/Delegate), and a background QThread to fetch data from a REST API so the GUI remains responsive.
Replace "https://api.example.com/items" and the JSON parsing logic in RestWorker::onReplyFinished with your actual REST endpoint and fields.
The RestWorker lives in its own thread to keep network calls off the GUI thread. The QNetworkAccessManager is created in that thread, and results are delivered to the GUI via Qt signals/slots.
The MyListModel is updated on the GUI thread by setDataItems, so you don't need explicit locks as long as you always mutate the model from the main thread.
You can trigger additional fetches using QMetaObject::invokeMethod(&worker, "fetchData", Qt::QueuedConnection); (e.g., on a timer or user action).