Suppose you have a custom built UI, with forms and c++ and such. Within certain panes/tabs/etc of this custom view, you want to display qml driven content. Is it possible for the same QML data to drive the output in multiple QDeclarativeView ?
I'm writing sort of a virtual table sort of application for RPG games. Here's the preliminary thoughts on how I am wanting to set it up.
- Application as a subclassed QDeclarativeView representing the scenario map. I subclass so that I may draw the map, grids, etc in a custom fashion.
- All the players/monsters/items/props/etc I would like to be provided as QML objects, for customization of behavior and such based on what is applicable for the game rules, etc.
- To narrow in one one example. Suppose QML defines a character for a D&D character, complete with stats, skills, etc. This object contains all this information.
- There is a list box, table view, or whatever in another pane of the application that shows the list of players, and I would like to be able to click on them and bring up their character sheet.
- I want this character sheet also to be created and managed by QML, presumably as part of the character QML object, since that's where all the data is.
How can the QML data/state be shared among different views like this? I would prefer not to have to have all the data driven elements instantiated inside the main map view if I don't have to. It would be far more flexible for example to have each character sheet rendered via different QML views on separate tab pages for example, for quick and easy access.
From my reading, it sounds as though I would need the declarative views in the character sheet UI to share the declarative context with their QML character instance, so that they share the same set of properties and such. Is this correct?
As far as displaying them separately, this is where I'm even more lost. Presumably I would have to parent the character sheet declarative item to the declarative view on the character tab(by passing it. If so, it would seem possibly not safe to break that parental link between those 2 components, because then the character sheet sub object would not be destroyed when the character object is destroyed?
I haven't tried it yet, but my initial thoughts on what to try is to have the character.qml object instantiate a charactersheet.qml object with component.createObject, passing the character sheet tab declarative view object as the parent, which I would presumably expose to the character object via a property somehow. Will this work? If so, how is the lifetime handled? Since it was instantiated by QML, would the garbage collector clean it up, despite the change in parental relationship?
In any case is there a better/cleaner/etc way to do this?
Alternately C++ can create the character qml object in the map view, and the character sheet component in the tab view, but then how would I configure them so they effectively access the same character data? Is that just a matter of just setting the character sheet object to the same declarative context as the character object?
Any help appreciated, thanks.