Description
Since 5.9, this method has been introduced:
static int QHostInfo::lookupHost(const QString &name, Functor functor)
While this is pretty much the same as the one using old style SLOT syntax, there is one difference which I believe should be considered as a bug:
As the documentation mentions, the internals of this method will be threaded, however, using the signal/slot syntax this would - afaiu - be decoupled again as signals/slots by default use Qt::QueuedConnections when different threads are involved. Using this Functor syntax tho, for example with a lambda will cause the lambda to be called from a different thread and I think that's not obvious.
I only noticed because I wrote such code:
QHostInfo::lookupHost("ufo.local", this, [this](const QHostInfo &host) { foreach (const QHostAddress &address, host.addresses()) { QNetworkRequest request("http://" + address.toString() + "/info"); QNetworkReply *reply = m_nam->get(request); ... } });
And that would not work unless QHostInfo's cache is filled. In that case it will directly emit cache results in the same thread as called, but if it actually does resolving, the callback will come from a different thread and break QNetworkAccessManager.
Now, I know how to get around this behavior, but IMO this behavior might cause quite bad bugs in applications as I would not expect it to behave this way.
Attachments
Issue Links
- duplicates
-
QTBUG-76276 QHostInfo weird behavior with functor
- Closed