У меня есть загрузчик со следующим кодом:
if(!_canceled) {
_reply = _accessManager.put(request, item);
if(_reply) {
_currentItem = item;
bool status = connect(_reply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(reportUploadProgress(qint64, qint64)));
pantheios::log(pantheios::debug, "StorageProvider(): connection uploadProgress(qint64, qint64), status", pantheios::boolean(status));
status = connect(_reply, SIGNAL(finished()), this, SLOT(handleFinishedRequest()));
pantheios::log(pantheios::debug, "StorageProvider(): connection finished(), status", pantheios::boolean(status));
} else {
emit noReply();
pantheios::log(pantheios::error, "StorageProvider(): no reply", item.toUtf8());
}
Затем в готовом слоте я делаю это:
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
if(reply->error() > QNetworkReply::NoError) {
pantheios::log(pantheios::error, "StorageProvider(handleFinishedRequest) ", reply->errorString().toUtf8());
if((reply->error() == QNetworkReply::TemporaryNetworkFailureError) || (reply->error() == QNetworkReply::ContentReSendError)) {
// retry the last request
_reply = accessManager.put(reply->request(), _currentItem);
}
} else {
...
}
Этот StorageProvider сможет обрабатывать различные запросы иОтвет будет иметь разные связи в зависимости от того, в какой функции он создан.Причина, по которой ответ является переменной-членом, заключается в том, что я могу удалить его, прежде чем выполнить следующий запрос.
Итак, мой вопрос: нужно ли мне снова устанавливать соединение, если я переиздаю ответ?Слот / сигнал подключен к указателю или объекту?Кроме того, есть ли лучший способ удалить старый ответ?
Редактировать: Изменен код на этот для обработчика законченного запроса;
if(_currentReply->error() > QNetworkReply::NoError) {
pantheios::log(pantheios::error, "StorageProvider(handleFinishedRequest) ", _currentReply->errorString().toUtf8());
if(((_currentReply->error() == QNetworkReply::TemporaryNetworkFailureError) || (_currentReply->error() == QNetworkReply::ContentReSendError)) && (_currentRetries < 4)) {
QNetworkRequest lastRequest = _currentReply->request();
_currentReply->deleteLater();
_currentReply = _accessManager.put(lastRequest, _currentItem);
if(_currentReply) {
bool status = connect(_currentReply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(reportUploadProgress(qint64, qint64)));
pantheios::log(pantheios::debug, "StorageProvider(retry): connection uploadProgress(qint64, qint64), status", pantheios::boolean(status));
status = connect(_currentReply, SIGNAL(finished()), this, SLOT(handleFinishedRequest()));
pantheios::log(pantheios::debug, "StorageProvider(retry): connection finished(), status", pantheios::boolean(status));
} else {
emit noReply();
pantheios::log(pantheios::error, "StorageProvider(retry): AccessManager no reply");
}
}
}