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
New Contributor
davidlondubat
Posts: 7
Registered: ‎09-18-2013
My Device: Z10

How save and open data using XML?

Hi,

I'm trying develop for BlackBerry and I'm new in this technology.

Now, I want create something like a form and save for the next time that user open the app is possible see the saved data there.

My problem is:
I don't know how do this, I saw the documentation(https://developer.blackberry.com/native/documentation/cascades/device_platform/data_access/working_w... but isn't clear for me(I don't know what put in .cpp, .hpp archieve, how call in the .qml, etc). You know some simple tutorial that can help?

Thank you for the attention!

Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How save and open data using XML?

Have you checked out the sample apps, there are xml examples and form apps there to look at...

 

http://developer.blackberry.com/native/sampleapps/


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
New Contributor
davidlondubat
Posts: 7
Registered: ‎09-18-2013
My Device: Z10

Re: How save and open data using XML?

Hi BBSJdev, yeah I saw the examples but there are a lot of functions, I just want know how I can save and load in xml in a simple way.

And also, I don't understanding how cascades conect with the c/c++ file.

Thank you for the attention.

Developer
joelajean
Posts: 132
Registered: ‎01-25-2010
My Device: Z30, Z10, Q10, Dev Alpha B & Bold 9900

Re: How save and open data using XML?

You can try the DataSource to read.... but I doubt it can save....

 

https://developer.blackberry.com/native/documentation/cascades/device_platform/data_access/using_dat...

 

Author of Shopping Cart Calculator, BP Monitor & Book-zy
@kodybb on Twitter

New Contributor
davidlondubat
Posts: 7
Registered: ‎09-18-2013
My Device: Z10

Re: How save and open data using XML?

What's the most easy way to save and read data with cascades, native development? theres some tutorial?

Thanks!

Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How save and open data using XML?

[ Edited ]

I prefer QXmlStreamReader and QXmlStreamWriter but there are plenty of other options.

 

Theres some example code here...

 

http://www.example8.com/category/view/id/8856

 

And on the Qt site of course...

 

http://developer.nokia.com/Community/Wiki/Generate_XML_programatically_in_Qt


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: How save and open data using XML?

If you are just trying to save simple bits of configuration data, QSettings is probably the way to go.

 

JSON is also pretty easy to work with, and SQLite is great for tables and lists of data.

 

To be honest, XML is a bit of a pain to work with, and I wouldn't generally recommend using it unless you already have some XML you need to deal with.

 

It's realy a matter of prefence though. If you like XML, go nuts, but if you are just trying to save some data to the file system and saw XML as an option first, there are lots of other ways.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
alecaserez
Posts: 18
Registered: ‎08-26-2012
My Device: Z10

Re: How save and open data using XML?

Hi, the solution.

 

void ApplicationUI::Request() {
	mListView = root->findChild<ListView*>("list");
	// Create a network access manager and connect a custom slot to its
	// finished signal
	mNetworkAccessManager = new QNetworkAccessManager(this);

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

	// Displays a warning message if there's an issue connecting the signal
	// and slot. This is a good practice with signals and slots as it can
	// be easier to mistype a slot or signal definition
	Q_ASSERT(result);
	Q_UNUSED(result);

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

	// Start the activity indicator
	mActivityIndicator->start();

	//variable para el query
	//QString queryString = "headphone";
	QString urlString = QString(
			"url http")
	// Create and send the network request
	QNetworkRequest request = QNetworkRequest();
	QUrl url(urlString);
	request.setUrl(QUrl(urlString));
	mNetworkAccessManager->get(request);
}

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

		// Abra el archivo e imprimir un error si el archivo no se puede abrir
		if (!mFile->open(QIODevice::ReadWrite | QFile::Truncate)) {
			qDebug() << "\n Failed to open file";
			return;
		}

		// Escribir en el archivo con los datos de respuesta y cierre el archivo
		mFile->write(reply->readAll());
		mFile->flush();
		mFile->close();

		// 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() + "/data.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();
	}
}

 

Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How save and open data using XML?

Have you changed your original requirement the title and OP mentioned XML?
This thread is likely to get all sorts of answers now.

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How save and open data using XML?

Please close of the thread if you are now looking for how to save and load data in a generic way.

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.