05-06-2013 10:13 AM
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);
The xml doesn't even get created, what is the correct way of creating the XML?
Solved! Go to Solution.
05-06-2013 10:38 AM
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.