mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-15 14:15:54 -06:00
[GH-ISSUE #166] property bindings are lost after connecting qml list models to the .Net models using "model: Net.toListModel()" #106
Labels
No labels
bug
enhancement
help wanted
help wanted
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/qmlnet#106
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MosiQt on GitHub (Sep 19, 2019).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/166
ListView in QML needs a ListModel to populate data. Also you need to define a delegate to define how data inside a model should be displayed in the view. (Link).
After working more than 10 years with Qt, I've found this as one of the best features of Qt/Qml. Most important, you can use property binding of model element in the delegates. It means by changing the model data, all the delegates will update theme-self. No extra refreshes are needed!
Now it seems that these property bindings are no longer working in qml.net. It's a huge drawback if there is no solution considered. I've prepared a simple example (The sample is attached):
This is a ListView in Qml with a simple delegate.

The data are comming from .Net model:

Whenever user clicks on the each row, I try to change title of that row:


The title is changed successfully yet we can't see the change in the view!

(the title is remained fixed though it's changed in the model)
Therefore it seems that the .Net models are making all property bindings gone unless there is a solution I'm not aware of that :) I'll appreciate if anyone can help me.
Example.zip
@pauldotknopf commented on GitHub (Sep 19, 2019):
You are declaring the
NotifySignal, but you aren't activating it when the value changes.See this: https://github.com/qmlnet/qmlnet/blob/develop/src/net/Qml.Net/Signals.cs
@MosiQt commented on GitHub (Sep 22, 2019):
Thanks Paul. Now I've added ActiveSignal call but not working yet. Let me know if I'm doing something wrong:

Should I register the "titleChanged" signal or connect it to somewhere?!
@MosiQt commented on GitHub (Sep 22, 2019):
Paul I've found the issue. The property binding is not working in delegates in qml. However it works when applying to ordinary qml items like Text. How can I make it works in delegates?
@pauldotknopf commented on GitHub (Sep 22, 2019):
Can you give me a minimal repo, maybe a repository somewhere I can clone?
@MosiQt commented on GitHub (Sep 22, 2019):
Check out this: https://github.com/MosiQt/TestQmlDotNet.git
Please check Views/MainFeed.qml (line: 33). Whenever user clicks on a list item, its title is changed (in C#) but the change is not affected in the list (delegate)
@MosiQt commented on GitHub (Sep 23, 2019):
@pauldotknopf
Also I've found 2 more clues that may be helpful (I've update the repo: https://github.com/MosiQt/TestQmlDotNet.git):
1- In the delegate (qml), always the last item is updated! So weird.
Look at this part of my repo code (FeedItemControl.qml) which is the list delegate definition:
In the example in repo, if you click on each row of the list, the three properties should be changed
and the view should be updated(since I've coded to be so) but only "updateTime" is updated in View. If you comment out the third label and re-run the app, this time only "summary" is updated (the last one)
2- and the last item is updated only once
In the previous example, if you click on each row the last item is updated. But if you re-click, then the last item is no longer updated!
@SwiTool commented on GitHub (Sep 26, 2019):
In fact I can reproduce this too. The first signal sent makes the good display (the first one in fact), but when I change other datas (and call
this.NotifySignal("xxxChanged")it does not update.Here is the code snippet :
Main.qml
AccountListItem.qml
AccountsController.cs
AccountModel.cs
Result :
Maybe i'm doing something wrong ?
@MosiQt commented on GitHub (Sep 26, 2019):
Yeah, seems a bug. What do you think Paul? @pauldotknopf
@SwiTool commented on GitHub (Sep 27, 2019):
Wow okay I got something. I think we're misusing the library.
Remember my line :
If I remove it, and let the one inside the
Task.Runmethod, it still doesn't refresh. It stays empty.I think the event loop refreshes the screen because of the
Initializemethod.As I can see, his project here works and I can't find any difference with things we did...
@MosiQt commented on GitHub (Sep 27, 2019):
Great. Anyway I'm not still get the solution. What's your solution to my example? (https://github.com/MosiQt/TestQmlDotNet.git)
@SwiTool commented on GitHub (Sep 27, 2019):
For your example, try to call :
in your
ViewModels/FeedViewModel.csinstead of calling the project's NotifySignal.
I'll make more tests with my example to understand and will get back soon
// sorry I edited because I wrote
this.NotifySignalinstead ofthis.ActivateSignal@SwiTool commented on GitHub (Sep 27, 2019):
I think the problem is (in your example) that you have NotifySignal in a class that is already instancied and is already itself having the NotifySignal attribute.
I'm doing the same in my example : AccountsController has [NotifySignal]Accounts which contains itself properties with [NotifySignal]. I think this is a bad practice (even not a practice to say right since it doesn't work).
Correct me if i'm wrong
-- The only thing I don't get right now is why it does not refresh even by calling
NotifySignalin aTask.Runmethod? I expect my data to be refreshed without any user interaction... Can you please tell ?@vadi2 commented on GitHub (Sep 27, 2019):
I haven't looked into this issue, but I use .NET models, async computation, and lists in my app successfully: https://github.com/health-validator/Hammer so maybe look into there for differences too.
@SwiTool commented on GitHub (Sep 27, 2019):
@vadi2 You're using
ActivateProperty, what is this for ? What is the difference withActivateSignal?I tried to use it here, look what it did :


Note that it is called in the
Task.Runmethod, in theComponent.onCompletedmethod.@vadi2 commented on GitHub (Sep 27, 2019):
You've got a class within a class? That won't work... already tried it. That's why my issues are now Lists: https://github.com/health-validator/Hammer/blob/master/Program.cs#L169
@SwiTool commented on GitHub (Sep 27, 2019):
So when you update a single property in a class containing dozens of it, you must refresh the "master" class via the
ActivateSignal("propertyNameOfClass")?@vadi2 commented on GitHub (Sep 27, 2019):
You can't nest classes within classes as you're saying - I've tried it, it doesn't work.
@vadi2 commented on GitHub (Sep 27, 2019):
https://github.com/health-validator/Hammer/pull/87 is where we realised the problem and ditched that approach, because just as you, we ran into this issue of properties inside nested classes not updating (and we figure it's not meant to be).
@SwiTool commented on GitHub (Sep 27, 2019):
Alright, but why it doesn't update with the
Task.Runmethod then ?@vadi2 commented on GitHub (Sep 27, 2019):
🤷♂️ I have not spent time investigating your usecase, sorry - but you're welcome to look at how Hammer does it, it works there.
@xsacha commented on GitHub (Nov 9, 2019):
The way the signals work, it cannot travel multiple classes deep. This makes sense because it is listening to a parent change first. If the parent has not changed, it will not look at the children.
You can avoid this entire scenario and simplify your code by using a local binding to the child's class.
Then any signals to that class children will be correctly notified.
@pauldotknopf commented on GitHub (Aug 21, 2020):
Hey guys, circling back to clean up issues.
First, I would avoid activating properties in background tasks. It should only be done in the GUI/Main thread.
Second, it's unclear if this issue is with Qml.Net, or the binding mechanism in Qml.