【发布时间】:2013-01-21 11:56:40
【问题描述】:
我正在尝试使用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*))); }这会造成灾难吗?还是应该为每个调用使用多个指针?
谢谢!
【问题讨论】: