Skip to content

Commit 9e882f0

Browse files
committed
cxx-qt-gen: use cxx-qt connectiontype and qmetaobjectconnection
1 parent 7802f3c commit 9e882f0

File tree

17 files changed

+186
-222
lines changed

17 files changed

+186
-222
lines changed

book/src/bridge/extern_rustqt.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,9 @@ using the signal name `<property>Changed` with no parameters.
225225
{{#include ../../../examples/qml_features/rust/src/signals.rs:book_signals_connect}}
226226
```
227227

228-
Each connection returns a [`QMetaObject::Connection`](https://doc.qt.io/qt-6/qmetaobject-connection.html) which is used to manage the connection.
228+
Each connection returns a [`QMetaObject::Connection`](https://doc.qt.io/qt-6/qmetaobject-connection.html) which can be used to manage the connection.
229229

230-
Note that the `QMetaObjectConnection` returned by CXX-Qt behaves a bit different from the Qt C++ implementation.
231-
232-
When the `QMetaObjectConnection` is dropped, it automatically disconnects the connection, similar to how a C++ `std::unique_ptr` or Rusts `Box` behaves.
233-
If you don't want to store the `QMetaObjectConnection`, call `release`, which will drop the object without disconnecting.
234-
In this case, it is no longer possible to disconnect later.
235-
236-
```rust,ignore,noplayground
237-
{{#include ../../../examples/qml_features/rust/src/signals.rs:book_signals_disconnect}}
238-
```
230+
> Note that a `QMetaObjectConnectionGuard` can be created from the `QMetaObject::Connection` which allows for RAII style disconnects
239231
240232
### Emitting a signal
241233

crates/cxx-qt-gen/src/generator/rust/property/mod.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ mod tests {
310310
#[doc = "Connect the given function pointer to the signal "]
311311
#[doc = "trivialPropertyChanged"]
312312
#[doc = ", so that when the signal is emitted the function pointer is executed."]
313-
#[must_use]
314-
pub fn connect_trivial_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection
313+
pub fn connect_trivial_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnection
315314
{
316315
ffi::MyObject_connect_trivial_property_changed(
317316
self,
@@ -331,13 +330,12 @@ mod tests {
331330
#[doc = ", so that when the signal is emitted the function pointer is executed."]
332331
#[doc = "\n"]
333332
#[doc = "Note that this method uses a AutoConnection connection type."]
334-
#[must_use]
335-
pub fn on_trivial_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection
333+
pub fn on_trivial_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnection
336334
{
337335
ffi::MyObject_connect_trivial_property_changed(
338336
self,
339337
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosuretrivialPropertyChanged>::new(Box::new(closure)),
340-
cxx_qt_lib::ConnectionType::AutoConnection,
338+
cxx_qt::ConnectionType::AutoConnection,
341339
)
342340
}
343341
}
@@ -438,8 +436,7 @@ mod tests {
438436
#[doc = "Connect the given function pointer to the signal "]
439437
#[doc = "opaquePropertyChanged"]
440438
#[doc = ", so that when the signal is emitted the function pointer is executed."]
441-
#[must_use]
442-
pub fn connect_opaque_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection
439+
pub fn connect_opaque_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnection
443440
{
444441
ffi::MyObject_connect_opaque_property_changed(
445442
self,
@@ -459,13 +456,12 @@ mod tests {
459456
#[doc = ", so that when the signal is emitted the function pointer is executed."]
460457
#[doc = "\n"]
461458
#[doc = "Note that this method uses a AutoConnection connection type."]
462-
#[must_use]
463-
pub fn on_opaque_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection
459+
pub fn on_opaque_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnection
464460
{
465461
ffi::MyObject_connect_opaque_property_changed(
466462
self,
467463
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosureopaquePropertyChanged>::new(Box::new(closure)),
468-
cxx_qt_lib::ConnectionType::AutoConnection,
464+
cxx_qt::ConnectionType::AutoConnection,
469465
)
470466
}
471467
}
@@ -566,8 +562,7 @@ mod tests {
566562
#[doc = "Connect the given function pointer to the signal "]
567563
#[doc = "unsafePropertyChanged"]
568564
#[doc = ", so that when the signal is emitted the function pointer is executed."]
569-
#[must_use]
570-
pub fn connect_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection
565+
pub fn connect_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnection
571566
{
572567
ffi::MyObject_connect_unsafe_property_changed(
573568
self,
@@ -587,13 +582,12 @@ mod tests {
587582
#[doc = ", so that when the signal is emitted the function pointer is executed."]
588583
#[doc = "\n"]
589584
#[doc = "Note that this method uses a AutoConnection connection type."]
590-
#[must_use]
591-
pub fn on_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection
585+
pub fn on_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut MyObject>, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnection
592586
{
593587
ffi::MyObject_connect_unsafe_property_changed(
594588
self,
595589
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosureunsafePropertyChanged>::new(Box::new(closure)),
596-
cxx_qt_lib::ConnectionType::AutoConnection,
590+
cxx_qt::ConnectionType::AutoConnection,
597591
)
598592
}
599593
}

0 commit comments

Comments
 (0)