Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Need help on program structure
Forum Updated to NodeBB v4.3 + New Features

Need help on program structure

Scheduled Pinned Locked Moved Brainstorm
5 Posts 2 Posters 2.2k Views 1 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.
  • B Offline
    B Offline
    BasicPoke
    wrote on last edited by
    #1

    Hopefully I can explain this. My Qt app can potentially interact with 4 different types of devices, but only one type at a time. There can be up to 8 devices at a time (all the same type). There are radio buttons to select the type of device. When the user clicks "Start", a different function is called depending on the type of device selected, let's call them ProcessDeviceA, ProcessDeviceB, etc.

    There is a list (currently QList) of up to 8 devices of the selected type, lets call the list Devices. Devices needs to be a different type, of course depending on the device type the user selected. The Devices list must be accessed in ProcessDeviceA, ProcessDeviceB, etc. ProcessDeviceA must access Devices for its specific type of device, etc. There is really little in common between the different device types.

    At the module level, must I have 4 different lists DevicesA, DevicesB, etc. and just operate on whichever one is necessary in ProcessDeviceA, ProcessDeviceB, etc. Or can I use polymorphism somehow? This will ultimately be in an embedded environment so I need to conserve RAM.

    Thanks
    Ron

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

      Hi,

      What about having an abstract base class and then make your devices from it ?

      Your ProcessDeviceXXX functions can receive e.g. QList<Devices> and when doing the processing checks whether the device is of the correct type and if not just do nothing.

      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
      • B Offline
        B Offline
        BasicPoke
        wrote on last edited by
        #3

        That's a good idea, exactly the kind of thing I was looking for. Thanks.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BasicPoke
          wrote on last edited by
          #4

          SGaist, it seems the base class Device would be possibly be empty. In this case, should I use inheritance for this? My app will still have to check what mode the program is in to decide what functions to call. I'm not clear how inheritance can help me here, but it just seems like it could. I will keep thinking and reading.

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

            Indeed, an interface is also a possibility

            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