Skip to content

Commit

Permalink
examples: use new constructor trait for initialise
Browse files Browse the repository at this point in the history
Related to #13
  • Loading branch information
ahayzen-kdab authored and Be-ing committed Jul 12, 2023
1 parent 9a9dfed commit 26cb666
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 0 additions & 4 deletions examples/demo_threading/qml/MainWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ Window {

EnergyUsage {
id: energyUsage

// FIXME: have the ability to HandleInit so we can start the server
// https://github.com/KDAB/cxx-qt/issues/13
Component.onCompleted: startServer()
}

Image {
Expand Down
28 changes: 23 additions & 5 deletions examples/demo_threading/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ mod ffi {
/// A Q_INVOKABLE that returns the current power usage for a given uuid
#[qinvokable]
fn sensor_power(self: Pin<&mut qobject::EnergyUsage>, uuid: &QString) -> f64;

/// A Q_INVOKABLE which starts the TCP server
#[qinvokable]
fn start_server(self: Pin<&mut qobject::EnergyUsage>);
}

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

use crate::{
Expand Down Expand Up @@ -113,9 +111,29 @@ impl ffi::EnergyUsageQt {
0.0
}
}
}

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

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

fn new((): ()) -> EnergyUsage {
EnergyUsage::default()
}

/// A Q_INVOKABLE which starts the TCP server
fn start_server(mut self: Pin<&mut Self>) {
fn initialize(mut self: core::pin::Pin<&mut Self>, _arguments: Self::InitializeArguments) {
if self.rust().join_handles.is_some() {
println!("Already running a server!");
return;
Expand Down

0 comments on commit 26cb666

Please sign in to comment.