Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7657113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:56:29+00:00 2026-05-31T12:56:29+00:00

I have a uploader with the following code: if(!_canceled) { _reply = _accessManager.put(request, item);

  • 0

I have a uploader with the following code:

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());
    }

Then in the finished slot I do this:

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 {
    ...
}

This StorageProvider will be able to handle different request and the reply will have different connections depending on in what function it is created. The reason why the reply is a member variable is so that I can delete it before I do my next request.

So, my question is, do I have to do the connection again if I repoint the reply? Is the slot/signal connected to the pointer or the object? Also, is there any better way to delete the old reply?

Edit: Changed the code to this for the handeler of a finished request;

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");
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:56:30+00:00Added an answer on May 31, 2026 at 12:56 pm

    The signal is connected to the object, not to the pointer variable, so you have to make new connections each time.

    And to delete the reply, just call deleteLater() at the beginning of the finished() slot:

    QNetworkReply *reply =  qobject_cast<QNetworkReply*>(sender());
    reply->deleteLater();
    

    that way it will be deleted at the end of the slot execution.


    You can avoid using sender() by wrapping each request (the initial one plus all the retries) inside its own QObject derived class:

    class PutRequest : public QObject {
    Q_OBJECT
    private:
         QNetworkAccessManager *_manager;
         QNetworkReply *_reply;
         QIODevice *_item; // Or whatever type the second parameter of put is
    public:
         explicit PutRequest(QNetworkAccessManager *manager, QNetworkRequest *request, QIODevice *item, QObject *parent = 0)
           : QObject(parent), _manager, _reply(0), _item(item) 
         {            
             _reply = _manager.put(request, item);
             connectSignalsAndSlots();
         }       
    
    private:
         void connectSignalsAndSlots() {
             // to delete the reply if the PutRequest object is destroyed
             reply_->setParent(this);
             // since the reply is encapsulated, the object has to emit its own
             // upload progress signal
             connect(_reply, SIGNAL(uploadProgress(qint64, qint64)), this, SIGNAL(uploadProgress(qint64, qint64)));
             connect(_reply, SIGNAL(finished()), this, SLOT(handleFinishedRequest()));
         }
    
    private slots:
         void handleFinishedRequest() {
             _reply->deleteLater();
             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 = _manager.put(_reply->request(), _item);
                connectSignalsAndSlots();
             }
    
             } else {
             ...                 
                 emit finished(this);
             }         
         }
    signals:
         void uploadProgress(qint64, qint64);
         // emitted when the upload is successful (after the possible retries)
         void finished(PutRequest*);
    };
    

    And you would create the request like this:

    if(!_canceled) {
        PutRequest *putRequest = new PutRequest(_accessManager, request, item);
    
        // and you connect putRequest object signals to whatever you connected _reply to
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have MVC3 project & Valums file uploader . The code is following <script
I have the following code pasted below. For some reason, the response.redirect seems to
I have the following code in child window which is working but what I
I have the following javascript code, which is modified from the SimpleUpload demo in
I have the following JQUERY code that I'm expecting to return 3 json results
I am having trouble getting the bulk uploader to work. I have been following
I have following problem. I use this tutorial to creating a multiple file uploader:
I have uploaded the following simple HTML code to http://losthobbit.net/temp/anchor.html <!DOCTYPE HTML PUBLIC -//W3C//DTD
I have the following code to count visitors on my PHP site. It works
I have the following code on my model: has_attached_file :photo, :styles => { :small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.