QNativeIpcKey 类保持的本机 Key 可以用于 QSystemSemaphore and QSharedMemory . 更多...
头: | #include <QNativeIpcKey> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
Since: | Qt 6.6 |
enum class | Type { SystemV, PosixRealtime, Windows } |
QNativeIpcKey () | |
QNativeIpcKey (QNativeIpcKey::Type type ) | |
QNativeIpcKey (const QString & key , QNativeIpcKey::Type type = DefaultTypeForOs) | |
QNativeIpcKey (const QNativeIpcKey & other ) | |
QNativeIpcKey (QNativeIpcKey && other ) | |
~QNativeIpcKey () | |
bool | isEmpty () const |
bool | isValid () const |
QString | nativeKey () const |
void | setNativeKey (const QString & newKey ) |
void | setType (QNativeIpcKey::Type type ) |
void | swap (QNativeIpcKey & other ) |
QString | toString () const |
QNativeIpcKey::Type | type () const |
QNativeIpcKey & | operator= (const QNativeIpcKey & other ) |
QNativeIpcKey & | operator= (QNativeIpcKey && other ) |
const QNativeIpcKey::Type | DefaultTypeForOs |
QNativeIpcKey | fromString (const QString & text ) |
QNativeIpcKey::Type | legacyDefaultTypeForOs () |
size_t | qHash (const QNativeIpcKey & ipcKey , size_t seed ) |
size_t | qHash (const QNativeIpcKey & ipcKey ) |
void | swap (QNativeIpcKey & value1 , QNativeIpcKey & value2 ) |
bool | operator!= (const QNativeIpcKey & lhs , const QNativeIpcKey & rhs ) |
bool | operator== (const QNativeIpcKey & lhs , const QNativeIpcKey & rhs ) |
The QSharedMemory and QSystemSemaphore 类使用称为 Key 的系统范围标识符,标识其资源。Qt 封装低级 Key 值及 Key 类型是使用 QNativeIpcKey 类。
Those two classes also provide the means to create native keys from a cross-platform identifier, using QSharedMemory::platformSafeKey() and QSystemSemaphore::platformSafeKey(). Applications should never share the input to those functions, as different versions of Qt may perform different transformations, resulting in different native keys. Instead, the application that created the IPC object should communicate the resulting native key using the methods described below.
有关 Key 类型、特定平台局限性、及与旧 (或非 Qt) 应用程序互操作的细节,见 本机 IPC (进程间通信) 键 文档编制。这包括 Apple 平台沙盒应用程序的重要信息,包括凭借 Apple APP 商店获得的所有应用。
If the other process supports QNativeIpcKey, the best way of communicating is via the string representation obtained from toString () and parsing it using fromString (). This representation can be stored on a file whose name is well-known or passed on the command-line to a child process using QProcess::setArguments ().
If the other process does not support QNativeIpcKey, then the two processes can exchange the nativeKey () but the older code is likely unable to adjust its key type. The legacyDefaultTypeForOs () function returns the type that legacy code used, which may not match the DefaultTypeForOs constant. This is still true even if the old application is not using the same build as the new one (for example, it is a Qt 5 application), provided the options passed to the Qt configure script are the same.
When communicating with non-Qt processes, the application must arrange to obtain the key type the other process is using. This is important particularly on Unix systems, where both PosixRealtime and SystemV are common.
The format of the string representation of a QNativeIpcKey is meant to be stable and therefore backwards and forwards compatible, provided the key type is supported by the Qt version in question. That is to say, an older Qt will fail to parse the string representation of a key type introduced after it was released. However, successfully parsing a string representation does not imply the Qt classes can successfully create an object of that type; applications should verify support using QSharedMemory::isKeyTypeSupported() and QSystemSemaphore::isKeyTypeSupported().
The format of the string representation is formed by two components, separated by a colon (':'). The first component is the key type, described in the table below. The second component is a type-specific payload, using percent-encoding . For all currently supported key types, the decoded form is identical to the contents of the nativeKey () field.
键类型 | 字符串表示 |
PosixRealtime |
"posix"
|
SystemV |
"systemv"
|
Windows |
"windows"
|
非标 SystemV |
"systemv-"
之后紧跟十进制数字
|
This format resembles a URI and allows parsing using URI/URL-parsing functions, such as QUrl . When parsed by such API, the key type will show up as the scheme , and the payload will be the path . Use of query or fragments is reserved.
另请参阅 QSharedMemory and QSystemSemaphore .
This enum describes the backend type for the IPC object. For details on the key types, see the 本机 IPC (进程间通信) 键 文档编制。
常量 | 值 | 描述 |
---|---|---|
QNativeIpcKey::Type::SystemV
|
0x51
|
X/Open System Initiative (XSI) or System V (SVr4) API |
QNativeIpcKey::Type::PosixRealtime
|
0x100
|
IEEE 1003.1b (POSIX.1b) API |
QNativeIpcKey::Type::Windows
|
0x101
|
Win32 API |
[explicit constexpr noexcept]
QNativeIpcKey::
QNativeIpcKey
(
QNativeIpcKey::Type
type
)
构造 QNativeIpcKey object holding native key key (or empty on the overload without the parameter) for type type .
[noexcept]
QNativeIpcKey
&QNativeIpcKey::
operator=
(
QNativeIpcKey
&&
other
)
[noexcept]
QNativeIpcKey::
QNativeIpcKey
(
QNativeIpcKey
&&
other
)
Copies or moves the content of other .
[constexpr noexcept]
QNativeIpcKey::
QNativeIpcKey
()
Constructs a QNativeIpcKey object of type DefaultTypeForOs with an empty key.
[noexcept]
QNativeIpcKey::
~QNativeIpcKey
()
Disposes of this QNativeIpcKey 对象。
[static]
QNativeIpcKey
QNativeIpcKey::
fromString
(const
QString
&
text
)
Parses the string form text and returns the corresponding QNativeIpcKey . String representations are useful to inform other processes of the key this process created and they should attach to.
If the string could not be parsed, this function returns an invalid 对象。
另请参阅 toString () 和 isValid ().
[noexcept]
bool
QNativeIpcKey::
isEmpty
() const
返回 true 若 nativeKey () 为空。
另请参阅 nativeKey ().
[noexcept]
bool
QNativeIpcKey::
isValid
() const
Returns true if this object contains a valid native IPC key type. Invalid types are usually the result of a failure to parse a string representation using fromString ().
This function performs no check on the whether the key string is actually supported or valid for the current operating system.
另请参阅 type () 和 fromString ().
[static noexcept]
QNativeIpcKey::Type
QNativeIpcKey::
legacyDefaultTypeForOs
()
返回 Type that corresponds to the native IPC key that QSharedMemory and QSystemSemaphore used to use prior to Qt 6.6. Applications and libraries that must retain compatibility with code using either class that was compiled with Qt prior to version 6.6 can use this function to determine what IPC type the other applications may be using.
Note that this function relies on Qt having been built with identical configure-time options.
[noexcept]
QString
QNativeIpcKey::
nativeKey
() const
Returns the native key string associated with this object.
另请参阅 setNativeKey () 和 type ().
Sets the native key for this object to newKey .
另请参阅 nativeKey () 和 setType ().
[constexpr]
void
QNativeIpcKey::
setType
(
QNativeIpcKey::Type
type
)
把此节点的 IPC (进程间通信) 类型设为 type .
另请参阅 type () 和 setNativeKey ().
[noexcept]
void
QNativeIpcKey::
swap
(
QNativeIpcKey
&
other
)
交换本机 IPC (进程间通信) 键和类型 other 与此对象。此操作非常快且从不失败。
Returns the string representation of this object. String representations are useful to inform other processes of the key this process created and that they should attach to.
This function returns a null string if the current object is invalid .
另请参阅 fromString ().
[constexpr noexcept]
QNativeIpcKey::Type
QNativeIpcKey::
type
() const
返回此对象关联的键类型。
另请参阅 nativeKey () 和 setType ().
This constant expression variable holds the default native IPC type for the current OS. It will be Type::Windows 对于 Windows 系统和 Type::PosixRealtime elsewhere. Note that this constant is different from what QSharedMemory and QSystemSemaphore defaulted to on the majority of Unix systems prior to Qt 6.6; see legacyDefaultTypeForOs () 了解更多信息。
[noexcept]
bool
operator!=
(const
QNativeIpcKey
&
lhs
, const
QNativeIpcKey
&
rhs
)
[noexcept]
bool
operator==
(const
QNativeIpcKey
&
lhs
, const
QNativeIpcKey
&
rhs
)
返回 true 若 lhs and rhs objects hold the same (or different) contents.
[noexcept]
size_t
qHash
(const
QNativeIpcKey
&
ipcKey
,
size_t
seed
)
返回哈希值为 ipcKey ,使用 seed 做计算种子。
[noexcept]
size_t
qHash
(const
QNativeIpcKey
&
ipcKey
)
返回哈希值为
ipcKey
,使用默认种子
0
.
[noexcept]
void
swap
(
QNativeIpcKey
&
value1
,
QNativeIpcKey
&
value2
)
交换本机 IPC (进程间通信) 键和类型 value1 with value2 。此操作非常快且从不失败。