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
gdev001
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Help

I am trying to run code from following example:https://developer.blackberry.com/cascades/documentation/device_comm/networking/index.html (about HTTP connections).


This is my code in the constructor of my cpp file:

 

	 // Creates the network request and sets the destination URL
	 QNetworkRequest request = QNetworkRequest();
	 request.setUrl(QUrl("http://www.blackberry.com"));

	 // Creates the network access manager and connects a custom slot to its
	 // finished signal. Checks the return value for errors.
	 QNetworkAccessManager *networkAccessManager =
	         new QNetworkAccessManager(this);
	 bool res = connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)),
	         this, SLOT(requestFinished(QNetworkReply*)));

	 Q_ASSERT(res);

	 // Indicate that the variable res isn't used in the rest of the app, to prevent
	 // a compiler warning
	 Q_UNUSED(res);

	 // Sends the request
	 networkAccessManager->get(request);

 When I debug it the res variable is False after connect gets executed, is this the right behaviour???

thank you.

 

 

Please use plain text.
Developer
oliver_kranz
Posts: 216
Registered: ‎09-18-2009
My Device: Z10
My Carrier: O2

Re: Help

The API documentation says:

 

Returns true if the connection succeeds; otherwise returns false.

 

According to this documentation the connection does not seem to be successful.

Please use plain text.
Developer
gdev001
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: Help

[ Edited ]

I solved that problem, seems I had to add key word "public slots:"

in the header file. But now I am entountering a different issue.

I am trying to follow this example; https://developer.blackberry.com/cascades/documentation/device_comm/networking/tutorial_http_comm.ht...

I have compiled and managed to run basically the whole sample, but there is one issue I am encountering. In one of the final code snippets about requestFinished implementation:

 

void JSONSample::requestFinished(QNetworkReply* reply)
{
// Check the network reply for errors if (reply->error() == QNetworkReply::NoError) { // Open the file and print an error if the file cannot be opened if (!mFile->open(QIODevice::ReadWrite)) { qDebug() << "\n Failed to open file"; return; } // Write to the file using the reply data and close the file mFile->write(reply->readAll()); mFile->flush(); mFile->close();

// line marker ### // Create the data model using the contents of the file. The // location of the file is relative to the assets directory. XmlDataModel *dataModel = new XmlDataModel(); dataModel->setSource(QUrl("file://" + QDir::homePath() + "/model.xml")); // Set the new data model on the list and stop the activity indicator mListView->setDataModel(dataModel); mActivityIndicator->stop(); } else { qDebug() << "\n Problem with the network"; qDebug() << "\n" << reply->errorString(); }
}

 when I debug the program reaches the point which I have marked as "// line marker ###" in the code above. So, I expect the file model.xml to be created somewhere on my PC but I can't find it?? I had one empty model.xml file in my assets folder (which I created manually), but it never gets filled. Any help?

 

ps. note I am also calling this in the constructor of my class as mentioned on the web site:

    // Create a file in the application's data directory
    mFile = new QFile("data/model.xml");

 pps. And when I actually near the following line in debug:

 

 // Set the new data model on the list and stop the activity indicator
        mListView->setDataModel(dataModel);

 I get following exception once it gets executed:

 

No source available for "bb::cascades::ListView::setDataModel() at 0xb837eb47"

 

Any help would be greatly appreciated.

Please use plain text.
Developer
dishooom
Posts: 103
Registered: ‎12-31-2012
My Device: Blackberry 9810
My Carrier: Verizon

Re: Help

[ Edited ]

The 'data' folder that you are referring to can be seen from 'Target File System Navigator' pane in QNX momentics IDE. Within the Simulator  folder in this pane, look out for Sandbox->Data->yourfile.xml

 

https://developer.blackberry.com/cascades/documentation/device_platform/filesystem/

 

-Dishooom

 

Hope this helps :Angel:

Please use plain text.
Developer
gdev001
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: Help

Thanks the xml file is inside. The assertion I am getting with list view seems to be because smth is wrong with setting up the UI. This sample was using AbstractPane *root = qml->createRootNode<AbstractPane>(); which I think is deprecated for BB 10 SDK. But the functionality seems to work now thanks.
Please use plain text.