QNetworkReply asycn problem



  • Hello guys,

    I am trying in get a xml response from a server using QNetworkReply and because the response is done async, when i need the value returned by an object and i put it in a string, the value from string si empty "".

    someone could help me with a sugestion in how i can fix this async problem ?

    Kind Regards,
    Silviu



  • Refer this link will help you
    http://qt-project.org/doc/qt-4.7/qnetworkaccessmanager.html

    you can also try this:-

           @ QNetworkRequest request;
                request.setUrl(QUrl(fileURL));
                QNetworkAccessManager *downloadmanager = new QNetworkAccessManager(this);
                downloadreply = downloadmanager->get(request);
    
                connect(downloadreply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(onDownloadProgress(qint64,qint64)));
                connect(downloadmanager,SIGNAL(finished(QNetworkReply*)),this,SLOT(onFinished(QNetworkReply*)));
    

    void class::onFinished(QNetworkReply * reply )
    {
    switch(reply->error())
    {
    case QNetworkReply::NoError:
    {
    QByteArray Data=reply->readAll();
    //you have all the data in Data
    }break;
    default:{
    //handle exception;
    };
    }
    }
    }
    @



  • ok, I already have done this.

    But , for example, if i want to move Data in a method named QString getData() and then i create a new object and after this i call getData() the return string will be empty .

    Regards,
    Sil


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.