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
Posts: 7
Registered: ‎10-11-2009
My Device: Not Specified
Accepted Solution

Read/Write XML to device

Hi,

 

I am a noob to QT/C++ programming. I am trying to write and store XML file on the device but it is not working. Here is my code:

QFile* XFile = new QFile("asset:///info.xml");
bool test = XFile->open(QIODevice::WriteOnly);

if(test){
QXmlStreamWriter writer(XFile);
writer.setAutoFormatting(true);
writer.writeStartDocument();
writer.writeStartElement("book mark");
writer.writeAttribute("type", "Family");
writer.writeEndElement();
writer.writeEndDocument();
}

XFile->close();

 

The xml doesn't even get created, what is the correct way of creating the XML?

 

Thanks

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Read/Write XML to device

Hi,
It's not working because assets folder is read-only and "asset:///" notation is not supported for standard Qt classes.

 

You can store the data in data/ folder (which is readwrite) or shared/ folder which can be accessed by other applications too. This snippet shows how to create a file in data folder:

 

QString dataFolder = QDir::homePath();
QString fullName = dataFolder + "/" + fileName;
QFile newFile(fullName);

Btw, if you create QFile using operator new, do not forget to delete it.

Or just create it on stack like in the code above.

 


Andrey Fidrya, @zmeyc on twitter
New Contributor
Posts: 7
Registered: ‎10-11-2009
My Device: Not Specified

Re: Read/Write XML to device

It worked like a charm 

 

Thanks!