How to defer emitting signal?
-
Thanks all.
I don't know where QNetworkAccessMnager::createRequest is called, I guess the code is:
@
QNetworkReply* reply = networkAccessManager->createRequest();
connect(reply, SIGNAL(finished()), someObj, SLOG(someSlot()));
// reply->someMethod();
@Is there a method call like reply->someMethod() after connect? I want to emit signal in this method.
-
Gerolf: Something like this should work
@
class Dummy : public QObject
{
...
public:
void emitFinished();
signal:
void finished();
}QMyReply::QMyReply(...)
{
Dummy *dummy = new QObject(this);
connect(dummy, SIGNAL(finished()), SIGNAL(finished()), QueuedConnection);dummy->emitFinished();
}
@I didn't say it would be easier/cleaner, only that he could also use QueuedConnection :)
-
Hi mario,
but it makes the whole complex more complex, requires more memory and QObject event does not have a finished signal. So he needs to implement some object with that signal.
Then it would be easier to make a queued call to one self:"QMetaObject::invokeMethod": http://doc.qt.nokia.com/latest/qmetaobject.html#invokeMethod with some parameters for queued function call or use an internal own slot with queued connection (which a single shot timer also does).
-
Ah, sweet. I totally forgot about invokeMethod. The funny thing is that I recently considered to use invokeMethod myself to replace a switch/case statement by simply doing invokeMethod for a bunch of signals :)
But I agree, seems that timer is the easiest approach in this case.
-
-
Great! Thank you.
Thanks everyone.
[quote author="Gerolf" date="1301294329"]Hi mario,
but it makes the whole complex more complex, requires more memory and QObject event does not have a finished signal. So he needs to implement some object with that signal.
Then it would be easier to make a queued call to one self:"QMetaObject::invokeMethod": http://doc.qt.nokia.com/latest/qmetaobject.html#invokeMethod with some parameters for queued function call or use an internal own slot with queued connection (which a single shot timer also does).
[/quote]