Skip to content

Commit

Permalink
examples: use Result in qml_features and test_inputs
Browse files Browse the repository at this point in the history
Related to #404
  • Loading branch information
ahayzen-kdab committed Jul 19, 2023
1 parent 71cc538 commit 7fc3692
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions crates/cxx-qt-gen/test_inputs/invokables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ mod ffi {

#[qinvokable(cxx_virtual)]
fn invokable_virtual(self: &MyObject);

#[qinvokable]
fn invokable_result_tuple(self: &MyObject) -> Result<()>;

#[qinvokable]
fn invokable_result_type(self: &MyObject) -> Result<String>;
}

impl cxx_qt::Threading for MyObject {}
Expand Down
14 changes: 14 additions & 0 deletions crates/cxx-qt-gen/test_outputs/invokables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ MyObject::invokableVirtual() const
invokableVirtualWrapper();
}

void
MyObject::invokableResultTuple() const
{
const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex);
invokableResultTupleWrapper();
}

::rust::String
MyObject::invokableResultType() const
{
const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex);
return invokableResultTypeWrapper();
}

static_assert(alignof(MyObjectCxxQtThread) <= alignof(::std::size_t),
"unexpected aligment");
static_assert(sizeof(MyObjectCxxQtThread) == sizeof(::std::size_t[4]),
Expand Down
4 changes: 4 additions & 0 deletions crates/cxx-qt-gen/test_outputs/invokables.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class MyObject : public QObject
Q_INVOKABLE void invokableFinal() const final;
Q_INVOKABLE void invokableOverride() const override;
Q_INVOKABLE virtual void invokableVirtual() const;
Q_INVOKABLE void invokableResultTuple() const;
Q_INVOKABLE ::rust::String invokableResultType() const;
MyObjectCxxQtThread qtThread() const;
explicit MyObject(::std::int32_t arg0, QObject* arg1);

Expand All @@ -50,6 +52,8 @@ class MyObject : public QObject
void invokableFinalWrapper() const noexcept;
void invokableOverrideWrapper() const noexcept;
void invokableVirtualWrapper() const noexcept;
void invokableResultTupleWrapper() const;
::rust::String invokableResultTypeWrapper() const;
explicit MyObject(
cxx_qt::my_object::cxx_qt_my_object::CxxQtConstructorArguments0&& args);

Expand Down
10 changes: 10 additions & 0 deletions crates/cxx-qt-gen/test_outputs/invokables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ mod ffi {
#[cxx_name = "invokableVirtualWrapper"]
fn invokable_virtual(self: &MyObject);
}
extern "Rust" {
#[doc(hidden)]
#[cxx_name = "invokableResultTupleWrapper"]
fn invokable_result_tuple(self: &MyObject) -> Result<()>;
}
extern "Rust" {
#[doc(hidden)]
#[cxx_name = "invokableResultTypeWrapper"]
fn invokable_result_type(self: &MyObject) -> Result<String>;
}
unsafe extern "C++" {
#[doc(hidden)]
type MyObjectCxxQtThread = cxx_qt::CxxQtThread<MyObject>;
Expand Down
6 changes: 3 additions & 3 deletions examples/qml_features/rust/src/invokables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod qobject {
unsafe extern "RustQt" {
/// Immutable invokable method that returns the QColor
#[qinvokable]
fn load_color(self: &RustInvokables) -> QColor;
fn load_color(self: &RustInvokables) -> Result<QColor>;

/// Mutable invokable method that stores a color
#[qinvokable]
Expand Down Expand Up @@ -61,8 +61,8 @@ impl Default for RustInvokablesRust {
// ANCHOR: book_invokable_impl
impl qobject::RustInvokables {
/// Immutable invokable method that returns the QColor
fn load_color(&self) -> QColor {
self.as_qcolor()
fn load_color(&self) -> Result<QColor, i32> {
Ok(self.as_qcolor())
}

/// Mutable invokable method that stores a color
Expand Down

0 comments on commit 7fc3692

Please sign in to comment.