JuliaGraphics / QML.jl

Build Qt6 QML interfaces for Julia programs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accessing elements of ListModel on qml side

janstenner opened this issue · comments

Hi!

First off, I really appreciate this library and love working with it so far.

Now, I wanted to synchronize an array between julia and qml - so I went with the ListModel Option.
As long as I use the model in a Repeater on the qml side it works as intended.

I run into problems when I want to use the Elements of the model in another function on the qml side.
When I create a ListModel in qml itself I can use the get(i) function to access the elements but when I do the same with a ListModel that I created on the julia side I get
TypeError: Property 'get' of object qmlwrap::ListModel(0xb777e990) is not a function

Am I right in assuming that the ListModels coming from julia are not "real" ListModels on the qml side but some similar construct that works with Repeaters and ListViews?
But then the Repeaters and ListViews must have a way of accessing the elements - can I use that somehow in my own code?

I remember that some time ago I encountered a similar issue where I wanted to use a setProperty. After researching I found a way to access the elements by index through ListView. I think it was something like myDelegateModel.items.get(currentIndex).model but I am not sure about it. Since then though I managed to refactor that out and update the listmodel in place.

Thank you, that points me in a good direction.
Sadly ".items" does not work. I also tried a few other names but I am just tapping in the dark.

I found this repo which shows how a lot of these qmlwrap classes are built but it does not contain ListModel:
https://github.com/barche/jlqml/tree/main

I assume you do not have any version control on your code so you can take a look into the old code to find out how it was exactly, right?

Unfortunately, I did not commit the code initially and can't see how exactly I managed to get particular elements. Perhaps my memory failed me, and I could not access elements from the qmlwrap ListModel instance. I remember having to refactor things until I could get the qmlwrap list model to work.

I now deal with such a situation by creating a QML signal that Julia can handle. For instance, I have a castBallot signal in https://github.com/PeaceFounder/PeaceFounderGUI/blob/main/qml/Bridge.qml which reads out elements from a model and updates the view on the QML side. That also allows me to test the GUI. I use the same signal but handle them with QML ListModel's as can be seen in Prototype.qml.

In 0.8 ListModel was removed.