02-06-2013 01:42 AM
I am trying to run code from following example:https://developer.blackberry.com/cascades/document
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.
02-06-2013 03:16 AM
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.
02-06-2013 04:10 AM - edited 02-06-2013 04:15 AM
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/document
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.
02-06-2013 05:24 AM - edited 02-06-2013 05:25 AM
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/document
-Dishooom
Hope this helps ![]()
02-06-2013 05:57 AM