- Qt 6.6
- Qt Core
- C++ Classes
- QSharedMemory
- Qt 6.6.1 Reference Documentation

# Obsolete Members for QSharedMemory

The following members of class QSharedMemory are deprecated. They are provided to keep old source code working. We strongly advise against using them in new code.

## Public Functions

`(deprecated)` | QSharedMemory(const QString &key, QObject *parent = nullptr)
`(deprecated)` QString | key() const
`(deprecated)` void | setKey(const QString &key)

## Member Function Documentation

### QSharedMemory::QSharedMemory(const QString &key, QObject *parent = nullptr)

This function is deprecated. We strongly advise against using it in new code.

Constructs a shared memory object with the given parent and with the legacy key set to key. Because its key is set, its create() and attach() functions can be called.

Legacy keys are deprecated. See Native IPC Keys for more information.

See also setKey(), create(), and attach().

### QString QSharedMemory::key() const

This function is deprecated. We strongly advise against using it in new code.

Returns the legacy key assigned with setKey() to this shared memory, or a null key if no key has been assigned, or if the segment is using a nativeKey(). The key is the identifier used by Qt applications to identify the shared memory segment.

You can find the native, platform specific, key used by the operating system by calling nativeKey().

See also setKey() and setNativeKey().

### void QSharedMemory::setKey(const QString &key)

This function is deprecated. We strongly advise against using it in new code.

This is an overloaded function.

Sets the legacy key for this shared memory object. If key is the same as the current key, the function returns without doing anything. Otherwise, if the shared memory object is attached to an underlying shared memory segment, it will detach from it before setting the new key. This function does not do an attach().

You can call key() to retrieve the legacy key. This function is mostly the same as:

     shm.setNativeKey(QSharedMemory::legacyNativeKey(key));

except that it enables obtaining the legacy key using key().

See also key(), nativeKey(), and isAttached().