Skip to content

Commit

Permalink
QML Features: Add constructor to Signals page.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonMatthesKDAB committed Jul 6, 2023
1 parent 600d5a1 commit e8b0c5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 0 additions & 2 deletions examples/qml_features/qml/pages/SignalsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Page {

RustSignals {
id: rustSignals

Component.onCompleted: initialise()
}

ColumnLayout {
Expand Down
28 changes: 23 additions & 5 deletions examples/qml_features/rust/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ pub mod ffi {
/// Disconnect
#[qinvokable]
fn disconnect(self: Pin<&mut qobject::RustSignals>);

/// Initialise the QObject, creating a connection reacting to the logging enabled property
#[qinvokable]
fn initialise(self: Pin<&mut qobject::RustSignals>);
}
// ANCHOR_END: book_rust_obj_impl

impl cxx_qt::Constructor<()> for qobject::RustSignals {}
}

use core::pin::Pin;
Expand All @@ -86,9 +84,29 @@ impl ffi::RustSignalsQt {
// Emit a signal to QML stating that we have disconnected
self.disconnected();
}
}

impl cxx_qt::Constructor<()> for qobject::RustSignals {
type BaseArguments = ();
type NewArguments = ();
type InitializeArguments = ();

fn route_arguments(
_: (),
) -> (
Self::NewArguments,
Self::BaseArguments,
Self::InitializeArguments,
) {
((), (), ())
}

fn new(_: Self::NewArguments) -> <Self as CxxQtType>::Rust {
Default::default()
}

/// Initialise the QObject, creating a connection reacting to the logging enabled property
fn initialise(self: Pin<&mut Self>) {
fn initialize(self: core::pin::Pin<&mut Self>, _: Self::InitializeArguments) {
self.on_logging_enabled_changed(|mut qobject| {
// Determine if logging is enabled
if *qobject.as_ref().logging_enabled() {
Expand Down

0 comments on commit e8b0c5d

Please sign in to comment.