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
使用しているように見えますが、ポインターを手動で削除しない方が安全ですか? スコープを離れて忘れますか?watcher
pendingcall のスマート ポインターにすべてのトリックを実行させることができる場合
QDBusPendingCallWatcher
、クラス内のポインターを 1 つだけ使用して、すべての非同期呼び出しを監視できますか? このような:{ 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*))); }
これは災害になりますか?または、呼び出しごとに複数のポインターを使用する必要がありますか?
ありがとう!