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. Is it possible to notify items in the model without signals?
QtWS25 Last Chance

Is it possible to notify items in the model without signals?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmodelindexsignal & slotabstractlist
6 Posts 4 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.
  • A Offline
    A Offline
    arguskso
    wrote on 26 Jun 2020, 00:41 last edited by
    #1

    Sorry if it's wrong place to ask, so my problem is I have a model which I derived from QAbstractListModel.
    which contains a list of objects with id. My application listens for a new data coming from a server so when new
    data is coming I loop over my list compare ids to receive object index, update the object and emit dataChanged signal to update a view.
    I have lots of these objects so I don't want to derive from QObject. I can use dict or something to map ids to indexes but
    I fill that I doing something wrong and there should be an easier solution to this problem

    J 1 Reply Last reply 26 Jun 2020, 01:04
    0
    • A arguskso
      26 Jun 2020, 00:41

      Sorry if it's wrong place to ask, so my problem is I have a model which I derived from QAbstractListModel.
      which contains a list of objects with id. My application listens for a new data coming from a server so when new
      data is coming I loop over my list compare ids to receive object index, update the object and emit dataChanged signal to update a view.
      I have lots of these objects so I don't want to derive from QObject. I can use dict or something to map ids to indexes but
      I fill that I doing something wrong and there should be an easier solution to this problem

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 26 Jun 2020, 01:04 last edited by
      #2

      Hi @arguskso, could you decribe what you mean by "notify items in the model"?

      I have lots of these objects so I don't want to derive from QObject

      Indeed, there is usually no need for objects that represent model data to inherit QObject.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      A 1 Reply Last reply 26 Jun 2020, 12:30
      0
      • J JKSH
        26 Jun 2020, 01:04

        Hi @arguskso, could you decribe what you mean by "notify items in the model"?

        I have lots of these objects so I don't want to derive from QObject

        Indeed, there is usually no need for objects that represent model data to inherit QObject.

        A Offline
        A Offline
        arguskso
        wrote on 26 Jun 2020, 12:30 last edited by arguskso
        #3

        @JKSH
        Maybe notify is a wrong word, imagine I have several objects in a list when a new data is coming I somehow update
        my object with a corresponding id in my model, but to update my view I have to know the index of the updated element to
        call dataChanged signal. Is there a better way to find index than just iterating and comparing ids?

        J 1 Reply Last reply 26 Jun 2020, 12:39
        0
        • A arguskso
          26 Jun 2020, 12:30

          @JKSH
          Maybe notify is a wrong word, imagine I have several objects in a list when a new data is coming I somehow update
          my object with a corresponding id in my model, but to update my view I have to know the index of the updated element to
          call dataChanged signal. Is there a better way to find index than just iterating and comparing ids?

          J Online
          J Online
          JonB
          wrote on 26 Jun 2020, 12:39 last edited by JonB
          #4

          @arguskso
          You have to generate the necessary/correct row/columns from model for the dataChanged signal. That's the whole basis models & views with QIndex() work in Qt. Whether there is a "a better way to find index than just iterating and comparing ids" is up to your design in your model. Yes, " I can use dict or something to map ids to indexes " is the way to make it faster.

          1 Reply Last reply
          1
          • A Offline
            A Offline
            arguskso
            wrote on 26 Jun 2020, 13:14 last edited by arguskso
            #5

            @JonB
            Objects can also be inserted at random place so updating indexes in a dict is not a solution,
            Now I thinking that delegates can send signals and know their index so I can pass id to the delegate.
            Connect all delegates with a signal and slot mechanism to my model (which is QObject) and when new
            data is coming I can emmit signal with an id and all delegates will receive it and one with the corresponding id will send one more
            signal back to the model with it's index in the model.
            But I fill like this is also not a very clean solution. Is there nothing well established for this kind of problem?

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 26 Jun 2020, 15:08 last edited by
              #6

              @arguskso said in Is it possible to notify items in the model without signals?:

              when new
              data is coming I can emmit signal with an id and all delegates will receive it and one with the corresponding id will send one more
              signal back to the model with it's index in the model.

              Delegates are used for displaying, they don't know anything about the internal data structure and don't have really access to anything else except it's own index. This can't work. You have to do it the way @JonB suggested to you.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2

              6/6

              26 Jun 2020, 15:08

              • Login

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