I have a valueTree that contains a load of project properties. Thanks to some very elegant methods I can easily write these properties to a settings files using:
ScopedPointer<XmlElement> data (propertyValueTree.createXml());
getUserSettings()->setValue ("PROJECT_SETTINGS", data);
However, I can’t seem to load the properties from my settings file into a new ValueTree? I thought that after I call setValue() I might be able to do something like this:
But it seems that newValueTree doesn’t contain any of the data that is stored in my settings file? Any ideas what I might be doing wrong? If it’s not obvious I can prepare a simple demo.
Thanks, that was a silly mistake to make! That has got me further, but there is a big difference between the xml that is created using getUserSettings()->setValue() and ValueTree::fromXml()? For example, I would have thought the following code would produce files there were more or less the same:
//write properties to settings file..
ScopedPointer<XmlElement> data (defaultValueTree.createXml());
getUserSettings()->setValue ("PROJECT_DEFAULT_SETTINGS", data);
//write new xml settings files based on data from user settings file, but using ValueTree
ScopedPointer<XmlElement> xmlData = getUserSettings()->createXml("PROPERTIES");
ValueTree newValueTree = ValueTree::fromXml(*xmlData);
XmlElement * el = newValueTree.createXml();
el->writeToFile(File("/home/rory/Desktop/NewSettings.xml"), String::empty);
delete el;
Maybe I’m making too many assumptions about how these two classes can work together?
Sorry to bump, but I’m still struggling with this. I just need to know if this should work, i.e, can I write ValueTree data as xml to a properties file, and then read the data back as xml to a new ValueTree object? If not I’ll simply try a different approach.
I don’t think you will be able to get this to work. ApplicationProperties are simply not in the format of a ValueTree. But it’s definitely something we should add to JUCE: some option to tell ApplicationProperties to save the properties as a ValueTree.
I’m afraid the easiest solution is to not use ApplicationProperties and to simply save/load the ValueTree. And maybe adding listeners to save the tree when things change.