woboq / qmetaobject-rs

Integrate Qml and Rust by building the QMetaObject at compile time.
MIT License
620 stars 89 forks source link

Is editing QML files in QtCreator's graphical editor supported? #293

Open andrew-otiv opened 11 months ago

andrew-otiv commented 11 months ago

I would like to be able to edit .qml files using qt's GUI tools. My understanding is that the intended way of using qmetaobject-rs is to always create a custom type from rust, register it with the QML engine, and hook it up to the rest of the GUI using signals, setters, etc...

However, when I try to load any of the qmetaobject-rs example qml files in QtCreator's Design mode, I get errors on the custom types similar to:

image

Do I just need to configure an import path somewhere, or is it currently impossible to use qmetaobject-rs and the gui tools together?

This is a possible duplicate of https://github.com/woboq/qmetaobject-rs/issues/242. I'm not sure if that ticket is limited to "Plugins", or if it's the same issue of QtCreator being unaware of any metadata that comes from the rust code.

Thanks! Andrew

andrew-otiv commented 11 months ago

As a workaround, is there a way to only expose the actual UI part of the QML to the QtCreator's Design mode? i.e. create a view with all the buttons using the UI, and then use it from another UML file with the types defined in rust?

(I'm still very new to Qt, and I realize learning it from the rust bindings is probably not the normal way)

ogoffart commented 11 months ago

I think new version of Qt needs a json with the metaobject information which is normally generated by moc, and that we do not generate. In principle, it should be possible to implement it such that the macro generate this file, although it wouldn't be very clean.

ratijas commented 11 months ago

If you write a library and install it somewhere on your qml import path, then it doesn't matter which language its native code was written — qmlplugindump or qmltyperegistrar would be able to find it either way to generate types info json. But if you are registering your types from your main executable, then you are out of luck. This problem in not specific to Rust bindings: if would be the same kind of pain point with C++ app.

That aside, in KDE I never heard of anyone using Qt Creator's GUI tool for editing QML. In my experience, mouse-driven development rarely works well, and you'll end up editing source code text a lot more anyway.

ogoffart commented 11 months ago

same kind of pain point with C++ app.

I think recent version of qt added the ability for moc to dump a json file, which is found by qtcreator for this kind of things, but i may be wrong.

ratijas commented 11 months ago

oh, that sounds cool. Having to run a separate external process after build has always sucked. Recently I found a plugin.qmltypes in our Kirigami repo that hasn't been automatically updates in half a decade! People were randomly adding and removing type declarations from it at first, but even then it was stuck at initial minor version 2.0. Clearly no one cared enough or even knew that it needed some care to be taken for one of the most core QML libraries in our infra.

andrew-otiv commented 11 months ago

Thanks for the feedbak @ogoffart and @ratijas!