pub trait Initialize: CxxQtType {
// Required method
fn initialize(self: Pin<&mut Self>);
}
Expand description
This trait can be implemented on any CxxQtType to automatically define a default constructor
that calls the initialize
function after constructing a default Rust struct.
Ensure that the impl cxx_qt::Constructor<()> for ... {}
is declared inside the CXX-Qt bridge.
Alternatively, using impl cxx_qt::Initialize for ... {}
acts as shorthand for the above line.
§Example
ⓘ
#[cxx_qt::bridge]
mod qobject {
extern "RustQt" {
#[qobject]
#[qproperty(i32, integer)]
type MyStruct = super::MyStructRust;
}
// Remember to tell the bridge about the default constructor
impl cxx_qt::Constructor<()> for MyStruct {}
// or
impl cxx_qt::Initialize for MyStruct {}
}
// Make sure the inner Rust struct implements `Default`
#[derive(Default)]
pub struct MyStructRust {
integer: i32,
}
impl cxx_qt::Initialize for qobject::MyStruct {
fn initialize(self: core::pin::Pin<&mut Self>) {
self.on_integer_changed(|qobject| {
println!("New integer value: {}", qobject.integer);
}).release();
}
}
Required Methods§
Sourcefn initialize(self: Pin<&mut Self>)
fn initialize(self: Pin<&mut Self>)
This function is called to initialize the QObject after construction.