How do I interact with an item from a list property?
-
I have an example project here https://github.com/jerkstorecaller/qmlregistertest , where GuildManager exposes the property "QList<Adventurer*> adventurers" to QML. Both GuildManager and Adventurer are registered to QML. I'm trying to understand how QML can interact with subobjects exposed via properties.
-
First, can I make Qt Creator provide me with autocomplete for a single Adventurer instance (obtained while iterating through the list) when editing a QML file? For example, within the "Add Adventurer" button's onClicked in main.qml. Calling adv.startQuesting() works, but I had no autocomplete support.
-
From my onClicked where I had GuildManager create a new adventurer, how can I connect signals from this adventurer instance to my QML, for example to write to the TextArea whenever adventurer emits currentTaskChanged(QString newtask)?
This is a learning exercise. I don't want to use GuildManager as a bridge for everything, as the app grows, it would make GuildManager too large, so I want to allow QML to interact with subitems directly. Imagine if this was several layers deep, for example a guild can have many parties, a party can have many adventurers, and an adventurer can have many controllable pets. To me it makes sense to have them accessed via QList<T> properties, and interact with the signals and Q_INVOKABLES of any instance at any depth. Let me know if you think this is wrong.
-
-
hi
@thierryhenry14 said in How do I interact with an item from a list property?:autocomplete
AFAIK there is no autocompletion possibility in this scenario for the moment.
@thierryhenry14 said in How do I interact with an item from a list property?:
From my onClicked where I had GuildManager create a new adventurer, how can I connect signals from this adventurer instance to my QML, for example to write to the TextArea whenever adventurer emits currentTaskChanged(QString newtask)?
see here https://doc.qt.io/qt-5/qtqml-javascript-expressions.html#connecting-signals-to-javascript-functions
adv.currentTaskChanged.connect(function(){ textArea.text = adv.currentTask; })