Solved How does QNetworkReply::finished() know which QNetworkReply object to use?
-
For example:
QNetworkReply * reply = m_network_manager.get(request); connect(reply, &QNetworkReply::finished, this, &network_reply_finished);
because the function
void network_reply_finished()
has no information about which reply to read
If using a member variable for QNetworkReply, it'll be not reentrant, or be complex to be reentrant.BTW, Instead
void QNetworkAccessManager::finished(QNetworkReply *reply)
knows which reply to read, but
QNetworkAccessManager
has no error signal, it seems incomplete.
-
One object for each download task can solve the problem.
Is there a better way? -
@jronald said in How does QNetworkReply::finished() know which QNetworkReply object to use?:
because the function
void network_reply_finished()has no information about which reply to read
It does - QObject::sender() will give you the reply object. Alternatively, you can map the signal with the help of QSignalMapper, or you can subscribe to the
QNetworkAccessManager
'sfinished(QNetworkReply *)
signal. -
Hi,
It's QNetworkReply that has the error signal and errorString which is human readable.
-
You can do something like this
void sendRequest() { QNetworkReply* reply = m_network_manager.get(request); connect(reply, &QNetworkReply::finished, this, &network_reply_finished); } void network_reply_finished() { QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender()); // use reply }