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 |
此類 相等可比較 .
| 枚舉類 | 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= (QNativeIpcKey && other ) |
| QNativeIpcKey & | operator= (const QNativeIpcKey & other ) |
| const QNativeIpcKey::Type | DefaultTypeForOs |
| QNativeIpcKey | fromString (const QString & text ) |
| QNativeIpcKey::Type | legacyDefaultTypeForOs () |
| size_t | qHash (const QNativeIpcKey & key , size_t seed = 0) |
| 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 對象保持本機鍵 key (or empty on the overload without the parameter) for type type .
[noexcept]
QNativeIpcKey
&QNativeIpcKey::
operator=
(
QNativeIpcKey
&&
other
)
[noexcept]
QNativeIpcKey::
QNativeIpcKey
(
QNativeIpcKey
&&
other
)
拷貝 (或移動) 內容為 other .
[constexpr noexcept]
QNativeIpcKey::
QNativeIpcKey
()
Constructs a QNativeIpcKey object of type DefaultTypeForOs with an empty key.
[noexcept]
QNativeIpcKey::
~QNativeIpcKey
()
處置此 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 無效 對象。
另請參閱 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
)
Swaps this native IPC key and type with 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 無效 .
另請參閱 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
&
key
,
size_t
seed
= 0)
返迴哈希值為 key ,使用 seed 做計算種子。
[noexcept]
void
swap
(
QNativeIpcKey
&
value1
,
QNativeIpcKey
&
value2
)
交換本機 IPC (進程間通信) 鍵和類型 value1 with value2 。此操作很快且從不失敗。