PDA

View Full Version : QNetworkReply readAll error



TorAn
21st September 2016, 01:13
(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:



void onResult(QNetworkReply* r)
{
QNetworkReply::NetworkError err = r->error(); // no error
bool isfin = r->isFinished(); // returns true;
qint64 bta = r->bytesAvailable(); // returns 988305 (correct size of a file I am trying to download)
r->setReadBufferSize(0); // to set read buffer to be unlimited size (per doc)
QByteArray ba(bta+1000,'0');
ba = r->readAll(); // UNHANDLED EXCEPTION at 0x5D8CA9E8 (msvcr120d.dll), qlist.h line 432
...
}

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:

class downloader : public QThread
{
Q_OBJECT
public:

downloadRebate() : QThread() {}
void run() {
_uploadman.reset(new QNetworkAccessManager());
..
connect(_uploadman.get(), SIGNAL(finished(QNetworkReply*)), this, SLOT(onResult(QNetworkReply*)));
_uploadman->get(upload);
exec();
}
private slots:
void onResult(QNetworkReply* r);
..
}

jefftee
21st September 2016, 03:12
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?

TorAn
21st September 2016, 04:36
Original code looked like that:

void onResult(QNetworkReply* r)
{
if (r == nullptr)
return;

QByteArray ba(r->readAll()); // error
...
}

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.