Value Tree In Application

Hello

I have a really simple application and I need to save an IP address and port number for next time its opened. I was going to do this in a value tree. I have used value trees in plug ins before and was surprised to find that it is different in applications. iv had a read of the tutorial doc but im not getting anywhere, much of the example code in the tutorial doc throws errors.

I am aware that I need to create a value tree and then attach a listener to my text box (Label) but I can’t work out how to get that far. once I have that I should be able to create and recall XMLs its just im falling at the first hurdle. Any one able to give me a few step by step pointers?

Rather than use a separate listener, and wiring up the connection between a ValueTree property and a GUI component yourself, I would recommend using JUCE’s PropertyComponents.

There are several subclasses of these. For an IP address and port number I’d guess you’d want the TextPropertyComponent (although if you wanted the user to choose from only a set number of options, you could instead use a ChoicePropertyComponent).

When you construct a PropertyComponent, you can give it a Value& valueToControl, which you can get from the ValueTree for a property using ValueTree::getPropertyAsValue.

Then the GUI and the ValueTree property connection is maintained by the PropertyComponent, and you don’t have to wire up your own listener scheme.

There may be an argument for implementing a scheme that is similar to the APVST attachments if concurrency is involved or if additional smartness is required for handling an undo manager, or if additional validation should be performed. For the simple cases PropertyComponent looks like a good approach though.