QDBusPendingReply Class
template <typename... Types> class QDBusPendingReplyQDBusPendingReply 클래스에는 비동기 메서드 호출에 대한 응답이 포함되어 있습니다. 더 보기...
헤더: | #include <QDBusPendingReply> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS DBus) target_link_libraries(mytarget PRIVATE Qt6::DBus) |
qmake: | QT += dbus |
상속합니다: | QDBusPendingReplyBase |
공용 타입
enum | anonymous { Count } |
공용 함수
QDBusPendingReply() | |
QDBusPendingReply(const QDBusMessage &message) | |
QDBusPendingReply(const QDBusPendingCall &call) | |
QDBusPendingReply(const QDBusPendingReply<Types...> &other) | |
QVariant | argumentAt(int index) const |
int | count() const |
QDBusError | error() const |
bool | isError() const |
bool | isFinished() const |
bool | isValid() const |
QDBusMessage | reply() const |
typename Select<0>::Type | value() const |
void | waitForFinished() |
typename Select<0>::Type | operator typename Select<0>::Type() const |
QDBusPendingReply<Types...> & | operator=(const QDBusMessage &message) |
QDBusPendingReply<Types...> & | operator=(const QDBusPendingCall &call) |
QDBusPendingReply<Types...> & | operator=(const QDBusPendingReply<Types...> &other) |
상세 설명
QDBusPendingReply는 가변 템플릿 클래스입니다. 템플릿 매개변수는 회신 데이터의 내용을 추출하는 데 사용되는 유형입니다.
이 클래스는 QDBusReply 와 기능이 비슷하지만 두 가지 중요한 차이점이 있습니다:
- QDBusReply 는 정확히 하나의 반환 유형만 허용하는 반면, QDBusPendingReply는 여러 유형을 가질 수 있습니다.
- QDBusReply 은 이미 완료된 회신에 대해서만 작동하는 반면, QDBusPendingReply는 보류 중인 호출의 회신을 기다릴 수 있습니다.
QDBusReply 으로 작성하는 경우
QDBusReply<QString> reply = interface->call("RemoteMethod"); if (reply.isValid()) // use the returned value useValue(reply.value()); else // call failed. Show an error condition. showError(reply.error());
와 같은 코드(응답 대기 중 차단 포함)를 작성할 수 있습니다:
QDBusPendingReply<QString> reply = iface->asyncCall("RemoteMethod"); reply.waitForFinished(); if (reply.isError()) // call failed. Show an error condition. showErrorD(reply.error()); else // use the returned value useValue(reply.value());
출력 인수가 두 개 이상인 메서드 호출의 경우 QDBusReply 을 사용하면 다음과 같이 작성할 수 있습니다:
reply = interface->call("RemoteMethod");
를 사용하는 반면, QDBusPendingReply를 사용하면 모든 출력 인수가 템플릿 매개 변수여야 합니다:
QDBusPendingReply<bool, QString> reply = iface->asyncCall("RemoteMethod"); reply.waitForFinished(); if (!reply.isError()) { if (reply.argumentAt<0>()) showSuccess(reply.argumentAt<1>()); else showFailure(reply.argumentAt<1>()); }
QDBusPendingReply 객체는 응답이 도착하면 신호를 방출하는 QDBusPendingCallWatcher 객체와 연결할 수 있습니다.
QDBusPendingCallWatcher 및 QDBusReply도 참조하세요 .
멤버 유형 문서
enum QDBusPendingReply::anonymous
상수 | 값 | 설명 |
---|---|---|
QDBusPendingReply::Count | std::is_same_v<typename Select<0>::Type, void> ? 0 : sizeof...(Types) | 응답에 포함될 것으로 예상되는 인자의 수입니다. |
멤버 함수 문서
QDBusPendingReply::QDBusPendingReply()
빈 QDBusPendingReply 객체를 만듭니다. 이 회신에 QDBusPendingCall 개체를 할당하지 않으면 QDBusPendingReply는 아무 작업도 수행할 수 없습니다. 모든 함수는 실패 값을 반환합니다.
QDBusPendingReply::QDBusPendingReply(const QDBusMessage &message)
메시지 message 에서 해당 내용을 가져올 QDBusPendingReply 객체를 만듭니다. 이 경우 이 객체는 이미 완료된 상태이며 응답의 내용에 액세스할 수 있습니다.
isFinished()도 참조하세요 .
QDBusPendingReply::QDBusPendingReply(const QDBusPendingCall &call)
call 보류 중인 비동기 호출에서 내용을 가져올 QDBusPendingReply 개체를 만듭니다. 이 QDBusPendingReply 개체는 call 와 동일한 보류 중인 호출 참조를 공유합니다.
QDBusPendingReply::QDBusPendingReply(const QDBusPendingReply<Types...> &other)
other QDBusPendingReply 객체의 복사본을 만듭니다. QDBusPendingCall 및 QDBusPendingCallWatcher 과 마찬가지로 이 QDBusPendingReply 개체도 동일한 보류 중인 호출 참조를 공유합니다. 모든 복사본은 동일한 반환 값을 공유합니다.
QVariant QDBusPendingReply::argumentAt(int index) const
회신 내용에서 index 위치에 있는 인수를 반환합니다. 회신에 요소가 많지 않은 경우 이 함수의 반환 값은 정의되지 않으므로(어설션 실패가 발생할 수 있음) 처리가 완료되었는지, 회신이 유효한지 확인하는 것이 중요합니다.
응답에 index 위치에 인수가 포함되어 있지 않거나 응답이 오류인 경우 이 함수는 잘못된 QVariant 을 반환합니다. D-Bus 메시지는 잘못된 QVariants를 포함할 수 없으므로 이 반환값을 사용하여 오류 상태를 감지할 수 있습니다.
[constexpr]
int QDBusPendingReply::count() const
응답에 포함되어야 하는 인수의 개수를 반환합니다. 이 숫자는 이 클래스에서 무효화되지 않은 템플릿 매개변수의 수와 일치합니다.
인수의 개수가 다르거나 유형이 다른 응답이 도착하면 잘못된 서명을 나타내는 오류 응답으로 변환됩니다.
QDBusError QDBusPendingReply::error() const
회신 메시지의 처리가 완료된 경우 회신 메시지의 오류 내용을 검색합니다. 회신 메시지의 처리가 완료되지 않았거나 정상적인 회신 메시지(오류 없음)가 포함된 경우 이 함수는 잘못된 QDBusError 을 반환합니다.
bool QDBusPendingReply::isError() const
응답에 오류 메시지가 포함되어 있으면 true
, 일반 메서드 응답이 포함되어 있으면 false를 반환합니다.
보류 중인 호출이 처리를 완료하지 않은 경우 이 함수는 true
도 반환합니다.
bool QDBusPendingReply::isFinished() const
보류 중인 호출 처리가 완료되고 응답이 수신된 경우 true
을 반환합니다. 이 함수가 true
를 반환하는 경우 isError(), error() 및 reply() 메서드는 유효한 정보를 반환해야 합니다.
이 함수는 waitForFinished()를 호출하거나 일반적으로 이벤트 루프 실행으로 돌아갈 때만 발생하는 외부 D-Bus 이벤트가 발생하는 경우에만 상태를 변경합니다.
QDBusPendingCallWatcher::isFinished()도 참조하세요 .
bool QDBusPendingReply::isValid() const
회신에 일반 회신 메시지가 포함되어 있으면 true
, 다른 메시지가 포함되어 있으면 false를 반환합니다.
보류 중인 호출이 처리를 완료하지 않은 경우 이 함수는 false를 반환합니다.
QDBusMessage QDBusPendingReply::reply() const
전송된 비동기 호출에 대해 처리가 완료된 경우 수신된 응답 메시지를 검색합니다. 보류 중인 호출이 완료되지 않은 경우 이 함수는 QDBusMessage::InvalidMessage 유형의 QDBusMessage 을 반환합니다.
처리가 완료되면 메시지 유형은 오류 메시지 또는 일반 메서드 응답 메시지가 됩니다.
typename Select<0>::Type QDBusPendingReply::value() const
이 응답의 첫 번째 인수를 반환하며, Types[0]
(이 클래스의 첫 번째 템플릿 매개변수) 유형으로 캐스팅합니다. 이는 argumentAt<0>()를 호출하는 것과 같습니다.
이 함수는 QDBusReply::value() 함수와 일치하는 편의상 제공됩니다.
응답이 도착하지 않은 경우 이 함수는 응답이 처리될 때까지 호출 스레드를 차단합니다.
응답이 오류 응답인 경우 이 함수는 기본값으로 구성된 Types[0]
객체를 반환하며, 이 객체는 유효한 값과 구별되지 않을 수 있습니다. 메시지가 오류인지 여부를 안정적으로 확인하려면 isError()를 사용하세요.
void QDBusPendingReply::waitForFinished()
응답을 수신하고 처리할 때까지 호출 스레드의 실행을 일시 중단합니다. 이 함수가 반환된 후 isFinished()는 회신 내용을 처리할 준비가 되었음을 나타내는 true를 반환해야 합니다.
QDBusPendingCallWatcher::waitForFinished()도 참조하세요 .
typename Select<0>::Type QDBusPendingReply::operator typename Select<0>::Type() const
이 응답의 첫 번째 인수를 반환하며, Types[0]
(이 클래스의 첫 번째 템플릿 매개변수) 유형으로 캐스팅합니다. 이는 argumentAt<0>()를 호출하는 것과 같습니다.
이 함수는 QDBusReply::value() 함수와 일치하는 편의상 제공됩니다.
응답이 도착하지 않은 경우 이 함수는 응답이 처리될 때까지 호출 스레드를 차단합니다.
응답이 오류 응답인 경우 이 함수는 기본값으로 구성된 Types[0]
객체를 반환하며, 이 객체는 유효한 값과 구별되지 않을 수 있습니다. 메시지가 오류인지 여부를 안정적으로 확인하려면 isError()를 사용하세요.
QDBusPendingReply<Types...> &QDBusPendingReply::operator=(const QDBusMessage &message)
이 객체가 message 메시지에서 내용을 가져오고 현재 보류 중인 호출에 대한 참조를 삭제합니다. 현재 참조가 완료되지 않은 보류 중인 호출에 대한 참조이고 이것이 마지막 참조인 경우 보류 중인 호출이 취소되고 회신 내용이 도착해도 이를 검색할 방법이 없습니다.
이 함수가 완료되면 QDBusPendingReply 개체는 "완료" 상태가 되고 message 콘텐츠에 액세스할 수 있습니다.
isFinished()도 참조하세요 .
QDBusPendingReply<Types...> &QDBusPendingReply::operator=(const QDBusPendingCall &call)
이 개체가 call 보류 중인 호출에서 내용을 가져오고 현재 보류 중인 호출에 대한 참조를 삭제합니다. 현재 참조가 완료되지 않은 보류 중인 호출에 대한 참조이고 이것이 마지막 참조인 경우 보류 중인 호출이 취소되고 회신 내용이 도착해도 이를 검색할 수 없습니다.
QDBusPendingReply<Types...> &QDBusPendingReply::operator=(const QDBusPendingReply<Types...> &other)
other 의 복사본을 만들고 현재 보류 중인 통화에 대한 참조를 삭제합니다. 현재 참조가 완료되지 않은 보류 중인 호출에 대한 참조이고 이것이 마지막 참조인 경우에는 보류 중인 호출이 취소되고 답장이 도착해도 답장의 내용을 검색할 수 없습니다.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.