Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ahayzen-kdab opened this issue Feb 28, 2024 Discussed in #871 · 0 comments · Fixed by #874 · May be fixed by Montel/cxx-qt#84
Closed

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

ahayzen-kdab opened this issue Feb 28, 2024 Discussed in #871 · 0 comments · Fixed by #874 · May be fixed by Montel/cxx-qt#84
Assignees
Labels
⬆️ feature New feature or request 🙋 good first issue Good for newcomers

Comments

@ahayzen-kdab
Copy link
Collaborator

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

Discussed in #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?

@ahayzen-kdab ahayzen-kdab added ⬆️ feature New feature or request 🙋 good first issue Good for newcomers labels Feb 28, 2024
Montel added a commit to Montel/cxx-qt that referenced this issue Feb 29, 2024
This was referenced Feb 29, 2024
Montel added a commit that referenced this issue Mar 1, 2024
* Implement PartialEq

close #873

* Add PartialEq in QPainterPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⬆️ feature New feature or request 🙋 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants