Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Design questions concerning a model for an REST-API
Forum Updated to NodeBB v4.3 + New Features

Design questions concerning a model for an REST-API

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 974 Views 2 Watching
  • 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.
  • _antipattern__ Offline
    _antipattern__ Offline
    _antipattern_
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • _antipattern__ Offline
        _antipattern__ Offline
        _antipattern_
        wrote on last edited by _antipattern_
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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