KDAB / cxx-qt

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

Missing equality trait on QImage (and maybe other new types? #873

Closed ahayzen-kdab closed 5 months ago

ahayzen-kdab commented 5 months ago

This is required because when the type is a Q_PROPERTY we generate Rust code that has ==

Discussed in https://github.com/KDAB/cxx-qt/discussions/871

Originally posted by **otiv-wannes-vanleemput** February 28, 2024 I want to visualise a Gstreamer pipeline which runs in a Rust backed. To start off, I would like to update a QImage with the current frame outputted by the pipeline. However, I'm unable to wrap a QImage in a custom rust struct. This is my cxxqt_object.rs file: ``` #[cxx_qt::bridge] pub mod qobject { unsafe extern "C++" { include!("cxx-qt-lib/qimage.h"); type QImage = cxx_qt_lib::QImage; } extern "RustQt" { #[qobject] #[qml_element] #[qproperty(QImage, video_frame)] type MyObject = super::MyObjectRust; } impl cxx_qt::Constructor<(QImage,), NewArguments=(QImage,)> for MyObject {} unsafe extern "RustQt" { #[qinvokable] fn video_frame_from_slice(self: Pin<&mut MyObject>, image: &[u8]); } } use core::pin::Pin; use cxx_qt_lib::{QImage}; pub struct MyObjectRust { video_frame: QImage, } impl cxx_qt::Constructor<(QImage,)> for qobject::MyObject { type BaseArguments = (); type InitializeArguments = (); type NewArguments = (QImage,); fn route_arguments(args: (QImage, )) -> (Self::NewArguments, Self::BaseArguments, Self::InitializeArguments) { (args, (), ()) } fn new((video_frame,): (QImage,)) -> MyObjectRust { MyObjectRust { video_frame, } } } impl qobject::MyObject { pub fn video_frame_from_slice(self: Pin<&mut Self>, image: &[u8]) { self.video_frame = QImage::from_data(image, None).unwrap(); } } ``` I tried deriving the Default trait, but this resulted in a build error. Thats why I used the constructor. However, I still get the following build error: ``` error[E0369]: binary operation `==` cannot be applied to type `cxx_qt_lib::QImage` --> src/cxxqt_object.rs:3:1 | 3 | #[cxx_qt::bridge] | ^^^^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `cxx_qt::bridge` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0369`. ``` Should I fork the repository and add the PartialEq trait to QImage, or am I using it incorrectly?