January 2016
Beginner
512 pages
12h 35m
English
A more elegant way that does not rely on sender() would be to use QSignalMapper and a local hash, in which all replies that are connected to that slot are stored. So, whenever you call QNetworkAccessManager::get(), store the returned pointer in a member variable of the QHash<int, QNetworkReply*> type and set up the mapper. Let's assume that we have the following member variables and that they are set up properly:
QNetworkAccessManager *m_nam; QSignalMapper *m_mapper; QHash<int, QNetworkReply*> m_replies;
Then, you connect the finished() signal of a reply this way:
QNetworkReply *reply = m_nam->get(QNetworkRequest(QUrl(/*...*/))); connect(reply, SIGNAL(finished()), m_mapper, SLOT(map())); ...