Results 1 to 3 of 3

Thread: QNetworkReply readAll error

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QNetworkReply readAll error

    (Qt 5.3 version) I have a strange situation with the code that I moved from one project to another. Used to work just fine... Here is the code:


    Qt Code:
    1. void onResult(QNetworkReply* r)
    2. {
    3. QNetworkReply::NetworkError err = r->error(); // no error
    4. bool isfin = r->isFinished(); // returns true;
    5. qint64 bta = r->bytesAvailable(); // returns 988305 (correct size of a file I am trying to download)
    6. r->setReadBufferSize(0); // to set read buffer to be unlimited size (per doc)
    7. QByteArray ba(bta+1000,'0');
    8. ba = r->readAll(); // UNHANDLED EXCEPTION at 0x5D8CA9E8 (msvcr120d.dll), qlist.h line 432
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 

    I am puzzled and will appreciate any advise or comment on what is going on and how to resolve it.

    Details:
    void onResult is a slot in a thread class:
    Qt Code:
    1. class downloader : public QThread
    2. {
    3. Q_OBJECT
    4. public:
    5.  
    6. downloadRebate() : QThread() {}
    7. void run() {
    8. _uploadman.reset(new QNetworkAccessManager());
    9. ..
    10. connect(_uploadman.get(), SIGNAL(finished(QNetworkReply*)), this, SLOT(onResult(QNetworkReply*)));
    11. _uploadman->get(upload);
    12. exec();
    13. }
    14. private slots:
    15. void onResult(QNetworkReply* r);
    16. ..
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by TorAn; 21st September 2016 at 01:22.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QNetworkReply readAll error

    Any chance your usage of setting the read buffer to unlimited is resulting in an out of memory condition and an invalid pointer results? Have you tried removing the call to setReadBuffer or setting to a fixed value to test?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkReply readAll error

    Original code looked like that:
    Qt Code:
    1. void onResult(QNetworkReply* r)
    2. {
    3. if (r == nullptr)
    4. return;
    5.  
    6. QByteArray ba(r->readAll()); // error
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 

    I also tried to set size of "ba" to fixed value greater then # of available bytes. Looks like the corruption of QNetworkReply instance, but I can't figure out why it happens.


    Added after 1 5 minutes:


    The issue is closed. It was a threading issue after all.
    Last edited by TorAn; 21st September 2016 at 04:36.

Similar Threads

  1. Replies: 9
    Last Post: 25th May 2015, 16:25
  2. SIGNAL in QNetworkReply error - SOLVED -
    By monillo in forum Qt Programming
    Replies: 4
    Last Post: 14th May 2015, 23:04
  3. How to find the error in QNetworkReply?
    By Gokulnathvc in forum Newbie
    Replies: 13
    Last Post: 20th April 2012, 11:40
  4. SOLVED: error: QNetworkReply: No such file or directory
    By TheIndependentAquarius in forum Qt Programming
    Replies: 0
    Last Post: 25th May 2011, 10:33
  5. QNetworkReply error handling
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 25th August 2009, 10:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.