KDAB / cxx-qt

Safe interop between Rust and Qt
https://kdab.github.io/cxx-qt/book/
964 stars 66 forks source link

How to wrap a rust crate and then use it in Qt ? #971

Closed dezbracaty closed 1 month ago

dezbracaty commented 1 month ago

As title says, If I have a rust crate bevy, and I want to wrap this crate ,and then use it in Qt , can I use cxx-qt to archive it ? If anyone can give me any idea or any example or tutorial thanks a lot ~!

LeonMatthesKDAB commented 1 month ago

Hi @dezbracaty , In general, yes, that's pretty much what CXX-Qt is meant for. You just add that crate as a dependency to your Cargo.toml and start creating QObjects with CXX-Qt that allow access to the functionality you want.

As bevy is pretty huge, has loads of functionality and acts more as a framework than a normal library it can be tricky to wrap in particular. What functionality exactly would you want to wrap from bevy? If you want to show the output of a bevy game in a Qt app, you may want to take a look at how we created a mini-browser for servo here: https://github.com/KDABLabs/cxx-qt-servo-webview There we embed the OpenGL context from servo into a QML application. Something similar may be possible with bevy.

dezbracaty commented 1 month ago

Hi @dezbracaty , In general, yes, that's pretty much what CXX-Qt is meant for. You just add that crate as a dependency to your Cargo.toml and start creating QObjects with CXX-Qt that allow access to the functionality you want.

As bevy is pretty huge, has loads of functionality and acts more as a framework than a normal library it can be tricky to wrap in particular. What functionality exactly would you want to wrap from bevy? If you want to show the output of a bevy game in a Qt app, you may want to take a look at how we created a mini-browser for servo here: https://github.com/KDABLabs/cxx-qt-servo-webview There we embed the OpenGL context from servo into a QML application. Something similar may be possible with bevy.

Wow, thanks for you replying ~! It's very useful. I will learn it . Thank you again!