Design questions concerning a model for an REST-API



  • Hi,

    I wrote a small application that allows interacting with a REST-API which only contains one Item. The application mostly consists of a ListView. For this I wrote my own model which inherits from QAbstractListModel and access the API via a Gateway. The gateway wraps a QNetworkAccessManager and handles de/-serialization of the objects (see image).
    I don't have a background in UIs so the asynchronous programming is pretty new to me and I'd like to hear feedback on my design choice. I was confused by the fact that the QNetworkAccessManager only exposes an asynchronous API while the QAbstractListModel's methods, e.g. 'removeRows' require me to return an boolean, indicating success. In my view it would be simpler if the initial call to the model was made asynchronously while the subsequent calls are synchronous. This would firstly not block the secondly allow me to remove my 'Job'-classes because they can be replaced by 'normal' functions with exception-based error handling. This would remove code complexity.
    Is my design okay for the use-case and if so, are my thoughts on it justified?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    One good source inspiration is the now deprecated qtenginio module which implements a custom list model that access a web service.

    Hope it helps



  • Thanks for posting this example. I looked into the code of qtenginio and it looks like they used an approach very similar to mine. It appears to be less boilerplate since they worked on the QJsonObjects directly.


  • Lifetime Qt Champion

    You're welcome !

    If that answers your question then please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.