Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How do I interact with an item from a list property?
Forum Updated to NodeBB v4.3 + New Features

How do I interact with an item from a list property?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 267 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thierryhenry14
    wrote on last edited by
    #1

    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.

    1. 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.

    2. 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.

    ODБOïO 1 Reply Last reply
    0
    • T thierryhenry14

      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.

      1. 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.

      2. 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.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      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;
                    })
      
      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved