Important: Please read the Qt Code of Conduct -

Qt5.4 using shared memory between objects of different types

  • 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.

  • Lifetime Qt Champion


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

  • 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.

  • Lifetime Qt Champion

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

Log in to reply