我正在尝试使用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在我的类中只使用一个指针来观察所有的异步调用吗?像这样:{ 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*))); }这会造成灾难吗?或者我应该为每个调用使用多个指针?
谢谢!