rust-qt / examples

Rust + Qt examples
149 stars 14 forks source link

How to use QAbstractListModel? #5

Open crziter opened 4 years ago

crziter commented 4 years ago

Hello,

Thank you very much for your great works! Can you provide an example of how to use QAbstractListModel with rust-qt? And further registering it to QML?

Best regards!

Riateche commented 4 years ago

It's not currently possible to use QAbstractListModel because inheritance is not supported yet. It's possible to work around it with QStandardItemModel in simple cases.

I don't know if it's possible to register QML types from Rust right now. It may require some special support, but I haven't looked into it yet.

jalcine commented 4 years ago

This is me being naive, but what prevents inheritance from being supported? Is it because of a trait-y thing in Rust? I figure a Rust-side implementation of those classes can be made.

Riateche commented 4 years ago

Nothing prevents supporting inheritance, it just wasn't implemented yet. Inheritance is a bit more complicated to support than straightforward calling of public methods because the generator has to set up an inherited class that allows to supply custom handlers for each virtual method. It should also provide a way to call protected methods because that's sometimes necessary. See https://github.com/rust-qt/ritual/issues/26 for a (slightly outdated) description of a possible approach.