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. Best approach to manage multiple instance model update ?

Best approach to manage multiple instance model update ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 127 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.
  • H Offline
    H Offline
    HubertDu47
    wrote on last edited by HubertDu47
    #1

    Hi everyone,

    I have nearly the same problem as here: https://forum.qt.io/topic/108042/how-to-emit-signal-dynamically, but instead of having pointer, I have QWeakPointer.

    I have an abstract class, say: "AModel", which have data to be updated. I create an instance for each "kind" of model (which is represented by an enum). I have a manager class "ManagerClass" which receives the data from a WebSocket and has to dispatch them to the right instance.
    The data are only stored if the user needs them, therefore, I only instantiate the "AModel" if the user ask them and I give to him a QSharedPointer. I only keep a QWeakPointer in the "ManagerClass", in case the user asks a kind of "AModel" currently used (I transform the QWeakPointer to strong ref, test if it's not null, and return it to the user (or if its null, creates a new instance)).

    The "ManagerClass" and the WebSocket are in a Thread "A" and the user uses a HMI in the main thread. (In the HMI thread the user can only get constant data and cannot modify class attributes)

    I only see three solutions to this problem:

    • Either every instance received all the messages and say: "this is not for me", but if I receive 1 message every 30ms, I will have 1 msg multiply by the instance number to manage. At first view, it doesn't seem really nice
    • Or I write a private signal in the "ManagerClass" (or in a companion class) for each kind of instance and connect this signal to the right instance at its creation
    • Or each time I received a message for an instance and I have a QWeakPointer, I transform it to a QSharedPointer (test if it's null) and call the method to update data. Seems to be the more elegant solution, but I don't know if there is one which can be better

    I'm stuck here and I don't know what will be the better solution (or if one better exists). What do you think about it?

    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