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. Qt5.4 using shared memory between objects of different types
Forum Update on Monday, May 27th 2025

Qt5.4 using shared memory between objects of different types

Scheduled Pinned Locked Moved General and Desktop
qt 5.4.1shared memory
4 Posts 2 Posters 1.4k 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
    ad5xj
    wrote on 17 Mar 2015, 16:55 last edited by
    #1

    Ok, here is the problem.

    The docs has an example of a shared memory item between two dialogs. However, I would like to share a memory segment between two objects of DIFFERENT types.

    For instance; I would create a struct to act as a control block of data in my main window (type QMainWindow/QWidget) that I would like to share with worker threads of type QObject or QThread that may or may not alter that data, but should use the values as common operating parameters. This in lieu of using persistent memory - like QSettings.

    The example is simple in that it just passes the shared memory to the second object as a dialog. But that is not possible with the same syntax if the second object is not the same type. Tried that - it doesn't work.

    So. What would I have to do to share my struct with a second or third object? Is this even possible? I am assuming it is, but this is the first time I have attempted this - hence my question.

    Ken AD5XJ

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Mar 2015, 21:43 last edited by
      #2

      Hi,

      QSharedMemory doesn't care about the type of object that is using it. What did you try and how did it fail ?

      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
      • A Offline
        A Offline
        ad5xj
        wrote on 19 Mar 2015, 19:11 last edited by
        #3

        That may be true; but, having not been able to do much to solve the problem I decided that the use of QSharedMemory is like swatting a fly with a sledge hammer in this situation.

        I am falling back to passing a reference to a data structure instead. That may be more appropriate.

        Ken AD5XJ

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 19 Mar 2015, 22:25 last edited by
          #4

          Were you using QSharedMemory to communicate between two objects of the same application ?

          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

          1/4

          17 Mar 2015, 16:55

          • Login

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