QDBusPendingCallWatcher
을 사용하여 비동기 호출을 보려고합니다. 이 같은 일부 샘플 코드 :QDBusPendingCallWatcher를 올바르게 사용하는 방법은 무엇입니까?
{
// interface = new QDBusInterface(...);
QDBusPendingCall pcall = interface->asyncCall("query");
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(handler(QDBusPendingCallWatcher*)));
}
및 핸들러 기능 :
void Client::handler(QDBusPendingCallWatcher* call)
{
QDBusPendingReply<QString> reply = *call;
// do something
}
내 질문
은이 :QDBusPendingCallWatcher
이
shared data pointer inside 사용처럼
그것은 안전 수동으로 삭제하지 않는 것입니다, 보이는
watcher
포인터? 범위를 벗어나서 잊어 버리시겠습니까?pendingcall의 스마트 포인터가 모든 트릭을 수행하도록 할 수 있다면 모든 클래스에서
QDBusPendingCallWatcher
포인터를 사용하여 모든 비동기 호출을 볼 수 있습니까? 이와 같이 :{ QDBusPendingCall pcall = interface->asyncCall("query"); watcher = new QDBusPendingCallWatcher(pcall, this); QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(handleOne(QDBusPendingCallWatcher*))); pcall = interface->asyncCall("anotherQuery"); watcher = new QDBusPendingCallWatcher(pcall, this); QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(handleTwo(QDBusPendingCallWatcher*))); }
이것은 재앙이됩니까? 또는 각 호출마다 여러 포인터를 사용해야합니까?
고마워요! QObject::deleteLater의 호출이 키가
void MyClass::callFinishedSlot(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<QString, QByteArray> reply = *call;
if (reply.isError()) {
showError();
} else {
QString text = reply.argumentAt<0>();
QByteArray data = reply.argumentAt<1>();
showReply(text, data);
}
call->deleteLater();
}
입니다 :
위의 코드에 의해 연결 슬롯은 다음과 유사한 수 :