I'm trying to use QDBusPendingCallWatcher
to watch an async call. Some sample code like this:
{
// interface = new QDBusInterface(...);
QDBusPendingCall pcall = interface->asyncCall("query");
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(handler(QDBusPendingCallWatcher*)));
}
and handler function:
void Client::handler(QDBusPendingCallWatcher* call)
{
QDBusPendingReply<QString> reply = *call;
// do something
}
My questions are:
It looks like
QDBusPendingCallWatcher
uses shared data pointer inside, is it safe to not manually delete thewatcher
pointer? Just leave the scope and forget it?If I can let the smart pointer of pendingcall to do all the tricks, can I use just one
QDBusPendingCallWatcher
pointer in my class to watch all the async calls? Like this:{ 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*))); }
Will this makes a disaster? Or should I use multiple pointers for each call?
Thanks!