Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 207
Registered: ‎02-10-2011
My Device: Playbook 16GB and Z10
My Carrier: Verizon

Re: QNetworkReply->readAll() causes SIGABRT

[ Edited ]
QObject *temp = sender();
	QNetworkReply *reply = qobject_cast<QNetworkReply*>(temp);
	qDebug() << "GMA: Request complete: " << reply->request().url().toString();
	QString response;
	if (reply->error() == QNetworkReply::NoError) {
		QSettings settings;
		if (authToken->isEmpty()) {
			
	            // removed as not relavent
		} else {
			if (bytes) {
				qDebug() << "GMA: Complete Bytes";
				QByteArray arr(reply->readAll());
				qDebug() << "GMA: Made it localized";
				emit complete(arr);
				reply->close();
			} else {
				qDebug() << "GMA: Complete String";
				emit complete(QString(reply->readAll()));
			}
		}
		
	} else {
		// login failed
		response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
		qDebug() << response;
	}
	reply->close();
	qDebug() << "GMA: Deleting reply";
	reply->deleteLater();
	qDebug() << "GMA: Finished deleting";

 Here it is.

 

It crashes after qDebug() << "GMA: Complete bytes";

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook
Developer
Posts: 207
Registered: ‎02-10-2011
My Device: Playbook 16GB and Z10
My Carrier: Verizon

Re: QNetworkReply->readAll() causes SIGABRT


Zmey wrote:

Please post the complete code.

 

UPD:

I've looked at the code but unable to see how it is supposed to work.

 

From my understanding the logic should be similar to this one:

 

1. Initialize networkReply member variable to NULL in constructor.

 

2. When request should be initiated, call QNetworkAccessManager's post() method. It returns a QNetworkReply instance.  Connect onFinished() slot to finished() signal of QNetworkReply. Store QNetworkReply in a member variable.

 

3. If user decided to stop the transfer, check if networkReply member variable is not NULL and call networkReply->stop() if it isn't. Do NOT destroy the reply yet.

 

4. In onFinished() slot check if any errors occured and if there is no errors, call readAll() and process the data. If there were errors do nothing. In both cases call deleteLater() on reply and set networkReply member variable to NULL. Do not call close() in onFinished(), it will be done automatically.

 


Ok, I did that and I am still having errors, not as frequently but still having them.  My guess is for whatever reason the buffer is corrupt tries to free memory before its fully read because in the end I am dealing with MB's worth of data being read into the buffer.

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook
Developer
Posts: 207
Registered: ‎02-10-2011
My Device: Playbook 16GB and Z10
My Carrier: Verizon

Re: QNetworkReply->readAll() causes SIGABRT

Strange behavior, I have noticed that it fails when I have byte's available in the reply.  I discovered this by :

 

qDebug() << "GMA: Buffer size: " << reply->readBufferSize();
qDebug() << "GMA: Bytes Available: " << reply->bytesAvailable();
qDebug() << "GMA: Bytes to Write: " << reply->bytesToWrite();

 Buffer size and Bytes to write are always 0 but if bytesAvailable > 0 then my app crashes.

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook
Highlighted
Developer
Posts: 207
Registered: ‎02-10-2011
My Device: Playbook 16GB and Z10
My Carrier: Verizon

Re: QNetworkReply->readAll() causes SIGABRT

Ok, so after HOURS of beating my head against walls, tables and doors I have come to the conclusion that QNetworkReply MAY release its buffer before QNetworkReply->readAll() is called for large (MB) worth of data.  So in order to fix this issue, I had to implement my own buffer for my network reply like so:

 

currentReply = networkAccessManager->post(request,byte);
connect(currentReply, SIGNAL(readyRead()), this, SLOT(readyRead()));

void UrlConnector::readyRead() {
	if (currentReply->error() == QNetworkReply::NoError) {
		if (!temp->open(QIODevice::WriteOnly | QIODevice::Append)) {
			qDebug() << "GMA: Unable to write to cache";
			return;
		}
		QByteArray data = currentReply->readAll();
		temp->write(data);
		temp->close();
	}
}

 That way I am in control of the data and its not stored in memory, its written to a file so I could avoid any possible memory errors.

 

Not sure if anyone else has experienced this.  But I do know that right now our platform is fragmented because the Verizon Z10 has OS version 10.0.9.2743 but when building an app DO NOT select this SDK to target the Verizon phones.  Target the latest 10.0.10.738 because if you target 10.0.9.2743 you will get all kinds of errors because some of the fixes from 10.0.10 were brought down to 10.0.9 which makes the numbers completely irrelavent!

 

But that is my rant.

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook