White-Oak / qml-rust

QML (Qt Quick) bindings for Rust language
MIT License
205 stars 18 forks source link

Changing engine properties inside slots #22

Closed flanfly closed 7 years ago

flanfly commented 7 years ago

I'm looking into replacing qmlrs with qml-rust in one of my projects. The backend of the application exposes its data using a bunch of QListModel instances to the fontend written in QML. When to user kicks off an action the QML side calls a slot of a singleton object. The slot handler code on the Rust side will do his thing and then update some of the QListModel instances and return. My problem is that I can't figure out how to get a hold of a reference to the QListModels. I tried to make them properties of the singleton which failed, I also had the idea to put the QmlEngine instance into a global static RwLock. Any ideas?

White-Oak commented 7 years ago

@flanfly Well, one of my app (it's pretty simple) Kefia uses QListModel as a data storage.

It uses a following approach:

That is what we have for now. I hope I described it okayish.

White-Oak commented 7 years ago

Also, properties are supported, but it is not really comfortable to use them due to limitations of macro system on stable Rust.

flanfly commented 7 years ago

Thanks for the quick answer! I did not know I have to write list instead of QListModel into the macro. I'll try that.

White-Oak commented 7 years ago

@flanfly you don't have to name it list, actually, any valid Rust identifier is good. Here are the docs with an example

flanfly commented 7 years ago

I got it to work, thanks.