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

Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified
Accepted Solution

QNetworkReply errorString "Premature end of document"

[ Edited ]

Has anyone experienced this issue?  The response comes back correctly for smaller responses (i.e. https://developer.blackberry.com/cascades/files/documentation/images/model.xml), but for larger replies, the response will contain some of the reply data, but not all of it (and I get the "Premature end of document" errorString).  Here is an example URL for a larger response: https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_...


The errorString seems to be coming from the QXmlStreamReader but the fact remains that the QNetworkReply has an incomplete response.


I've followed the HTTP Communication tutorial almost exactly.  Here is some relevant code:



void ApplicationUI::initiateRequest(QString username, QString password) {
	// Start the activity indicator

	// Create and send the network request
	QNetworkRequest request = QNetworkRequest();
	QUrl url("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_...");



void ApplicationUI::requestFinished(QNetworkReply* reply) {

	// Check the network reply for errors
	if (reply->error() == QNetworkReply::NoError) {

		qDebug() << "\n reply is: " << reply->readAll();

QXmlStreamReader xml;

QMLByteArray data = reply->readAll();

while(!xml.atEnd() && !xml.hasError()) {
// parse here
} /* Error handling. */ if (xml.hasError()) { qDebug() << "\n errorString is: " << xml.errorString(); } xml.clear(); mActivityIndicator->stop(); } else { qDebug() << "\n Problem with the network"; qDebug() << "\n" << reply->errorString(); } }



// Default empty project template
#ifndef ApplicationUI_HPP_
#define ApplicationUI_HPP_

#include <bb/cascades/ActivityIndicator>

using namespace bb::cascades;

namespace bb { namespace cascades { class Application; }}

 * @brief Application pane object
 *Use this object to create and init app UI, to create context objects, to register the new meta types etc.
class ApplicationUI : public QObject
    ApplicationUI(bb::cascades::Application *app);

    Q_INVOKABLE void login(QString username, QString password);

	 * Initiates the network request.
	Q_INVOKABLE void initiateRequest(QString username, QString password);

    virtual ~ApplicationUI() {}

private slots:
     * Handles the network reply.
    void requestFinished(QNetworkReply* reply);

    ActivityIndicator *mActivityIndicator;
    QNetworkAccessManager *mNetworkAccessManager;

#endif /* ApplicationUI_HPP_ */




// Default empty project template
#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

#include <bb/cascades/ActivityIndicator>

using namespace bb::cascades;

ApplicationUI::ApplicationUI(bb::cascades::Application *app)
: QObject(app)

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("app", this);

    AbstractPane *root = qml->createRootObject<AbstractPane>();

	mActivityIndicator = root->findChild<ActivityIndicator*>("indicator");

	// Create a network access manager and connect a custom slot to its
	// finished signal
	mNetworkAccessManager = new QNetworkAccessManager(this);

	bool result = connect(mNetworkAccessManager,
			this, SLOT(requestFinished(QNetworkReply*)));




I would appreciate any help!




Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: QNetworkReply errorString "Premature end of document"

My apologies, it looks like I posted a bit prematurely on this one.  The response came back in full.  There were a couple of red herrings that distracted me from the main problems:


  1. I was parsing the XML incorrectly
  2. It seems that if the response is too long in the device log, then the device log will trim the message.  Is there a way to configure the device log not to do this?
  3. It looks like the reply message was gone after using the following qDebug() statement.  Will this remove the data from "reply"?  I'm a C++ newbie, coming from Java...
    qDebug() << "\n reply is: " << reply->readAll();