Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsharedmemory.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSHAREDMEMORY_H
5#define QSHAREDMEMORY_H
6
7#include <QtCore/qtipccommon.h>
8#ifndef QT_NO_QOBJECT
9# include <QtCore/qobject.h>
10#else
11# include <QtCore/qobjectdefs.h>
12# include <QtCore/qscopedpointer.h>
13# include <QtCore/qstring.h>
14#endif
15
17
18#if QT_CONFIG(sharedmemory)
19
20class QSharedMemoryPrivate;
21
22class Q_CORE_EXPORT QSharedMemory : public QObject
23{
25 Q_DECLARE_PRIVATE(QSharedMemory)
26
27public:
28 enum AccessMode
29 {
31 ReadWrite
32 };
33 Q_ENUM(AccessMode)
34
35 enum SharedMemoryError
36 {
37 NoError,
38 PermissionDenied,
39 InvalidSize,
40 KeyError,
41 AlreadyExists,
42 NotFound,
43 LockError,
44 OutOfResources,
45 UnknownError
46 };
47 Q_ENUM(SharedMemoryError)
48
49 QSharedMemory(QObject *parent = nullptr);
50 QSharedMemory(const QNativeIpcKey &key, QObject *parent = nullptr);
51 ~QSharedMemory();
52
53 QSharedMemory(const QString &key, QObject *parent = nullptr);
54 void setKey(const QString &key);
55 QString key() const;
56
57 void setNativeKey(const QNativeIpcKey &key);
58 void setNativeKey(const QString &key, QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs())
59 { setNativeKey({ key, type }); }
60 QString nativeKey() const;
61 QNativeIpcKey nativeIpcKey() const;
62#if QT_CORE_REMOVED_SINCE(6, 5)
63 void setNativeKey(const QString &key);
64#endif
65
66 bool create(qsizetype size, AccessMode mode = ReadWrite);
67 qsizetype size() const;
68
69 bool attach(AccessMode mode = ReadWrite);
70 bool isAttached() const;
71 bool detach();
72
73 void *data();
74 const void* constData() const;
75 const void *data() const;
76
77#if QT_CONFIG(systemsemaphore)
78 bool lock();
79 bool unlock();
80#endif
81
82 SharedMemoryError error() const;
83 QString errorString() const;
84
85 static bool isKeyTypeSupported(QNativeIpcKey::Type type) Q_DECL_CONST_FUNCTION;
86 static QNativeIpcKey platformSafeKey(const QString &key,
87 QNativeIpcKey::Type type = QNativeIpcKey::DefaultTypeForOs);
88 static QNativeIpcKey legacyNativeKey(const QString &key,
89 QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs());
90
91private:
92 Q_DISABLE_COPY(QSharedMemory)
93};
94
95#endif // QT_CONFIG(sharedmemory)
96
98
99#endif // QSHAREDMEMORY_H
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
Q_MULTIMEDIA_EXPORT QString errorString(HRESULT hr)
#define Q_DECL_CONST_FUNCTION
DBusConnection const char DBusError * error
GLenum mode
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
@ NoError
Definition main.cpp:34
#define Q_ENUM(x)
#define Q_OBJECT
ptrdiff_t qsizetype
Definition qtypes.h:165
QReadWriteLock lock
[0]
mutex unlock()
setKey(0)
[0]
view create()