Skip to content

Commit 20ee58f

Browse files
Add a lifetime parameter to QMetaObjectConnectionGuard (#1263)
* cxx-qt: scoped connection signal handlers * cxx-qt-gen: scoped connection closures * cxx-qt-gen: update test cases * update changelog * cxx-qt-gen: fix test cases * make QMetaObjectConnectionGuard a type alias of QScopedMetaObjectConnectionGuard<'static> * cxx-qt-gen: fix test cases * cxx-qt: remove Send and Sync from QMetaObjectConnection --------- Co-authored-by: Leon Matthes <[email protected]>
1 parent 7aedb1d commit 20ee58f

File tree

13 files changed

+474
-369
lines changed

13 files changed

+474
-369
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- Support for `QMessageLogContext` and sending log messages to the Qt message handler.
3636
- Serde support for further types: `QByteArray`, `QSet`, `QStringList`, `QVector`, `QUrl`
3737
- Added `QEventLoop` to cxx-qt-lib-extras.
38+
- Add `QScopedMetaObjectConnectionGuard`, which is `QMetaObjectConnectionGuard` with a scoped lifetime. `QMetaObjectConnectionGuard` is now a type alias for `QScopedMetaObjectConnectionGuard<'static>`.
3839
- Support for setting Qt log message patterns with `q_set_message_pattern` and formatting log messages ith `q_format_log_message`.
3940

4041
### Removed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ mod tests {
280280
unsafe extern "C++" {
281281
#[doc(hidden)]
282282
#[namespace = "rust::cxxqtgen1"]
283-
type MyObjectCxxQtSignalHandlertrivialPropertyChanged = cxx_qt::signalhandler::CxxQtSignalHandler<super::MyObjectCxxQtSignalClosuretrivialPropertyChanged>;
283+
type MyObjectCxxQtSignalHandlertrivialPropertyChanged<'a> = cxx_qt::signalhandler::CxxQtSignalHandler<'a, super::MyObjectCxxQtSignalClosuretrivialPropertyChanged>;
284284

285285
#[doc(hidden)]
286286
#[namespace = "rust::cxxqtgen1"]
@@ -310,9 +310,9 @@ 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-
pub fn connect_trivial_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
313+
pub fn connect_trivial_property_changed<'a, F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QScopedMetaObjectConnectionGuard<'a>
314314
{
315-
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_trivial_property_changed(
315+
cxx_qt::QScopedMetaObjectConnectionGuard::from(qobject::MyObject_connect_trivial_property_changed(
316316
self,
317317
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosuretrivialPropertyChanged>::new(Box::new(closure)),
318318
conn_type,
@@ -330,9 +330,9 @@ mod tests {
330330
#[doc = ", so that when the signal is emitted the function pointer is executed."]
331331
#[doc = "\n"]
332332
#[doc = "Note that this method uses a AutoConnection connection type."]
333-
pub fn on_trivial_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QMetaObjectConnectionGuard
333+
pub fn on_trivial_property_changed<'a, F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QScopedMetaObjectConnectionGuard<'a>
334334
{
335-
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_trivial_property_changed(
335+
cxx_qt::QScopedMetaObjectConnectionGuard::from(qobject::MyObject_connect_trivial_property_changed(
336336
self,
337337
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosuretrivialPropertyChanged>::new(Box::new(closure)),
338338
cxx_qt::ConnectionType::AutoConnection,
@@ -353,7 +353,7 @@ mod tests {
353353
parse_quote! {
354354
impl cxx_qt::signalhandler::CxxQtSignalHandlerClosure for MyObjectCxxQtSignalClosuretrivialPropertyChanged {
355355
type Id = cxx::type_id!("::rust::cxxqtgen1::MyObjectCxxQtSignalHandlertrivialPropertyChanged");
356-
type FnType = dyn FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + Send;
356+
type FnType<'a> = dyn FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send;
357357
}
358358
},
359359
);
@@ -405,7 +405,7 @@ mod tests {
405405
unsafe extern "C++" {
406406
#[doc(hidden)]
407407
#[namespace = "rust::cxxqtgen1"]
408-
type MyObjectCxxQtSignalHandleropaquePropertyChanged = cxx_qt::signalhandler::CxxQtSignalHandler<super::MyObjectCxxQtSignalClosureopaquePropertyChanged>;
408+
type MyObjectCxxQtSignalHandleropaquePropertyChanged<'a> = cxx_qt::signalhandler::CxxQtSignalHandler<'a, super::MyObjectCxxQtSignalClosureopaquePropertyChanged>;
409409

410410
#[doc(hidden)]
411411
#[namespace = "rust::cxxqtgen1"]
@@ -435,9 +435,9 @@ mod tests {
435435
#[doc = "Connect the given function pointer to the signal "]
436436
#[doc = "opaquePropertyChanged"]
437437
#[doc = ", so that when the signal is emitted the function pointer is executed."]
438-
pub fn connect_opaque_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
438+
pub fn connect_opaque_property_changed<'a, F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QScopedMetaObjectConnectionGuard<'a>
439439
{
440-
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_opaque_property_changed(
440+
cxx_qt::QScopedMetaObjectConnectionGuard::from(qobject::MyObject_connect_opaque_property_changed(
441441
self,
442442
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosureopaquePropertyChanged>::new(Box::new(closure)),
443443
conn_type,
@@ -455,9 +455,9 @@ mod tests {
455455
#[doc = ", so that when the signal is emitted the function pointer is executed."]
456456
#[doc = "\n"]
457457
#[doc = "Note that this method uses a AutoConnection connection type."]
458-
pub fn on_opaque_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QMetaObjectConnectionGuard
458+
pub fn on_opaque_property_changed<'a, F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QScopedMetaObjectConnectionGuard<'a>
459459
{
460-
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_opaque_property_changed(
460+
cxx_qt::QScopedMetaObjectConnectionGuard::from(qobject::MyObject_connect_opaque_property_changed(
461461
self,
462462
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosureopaquePropertyChanged>::new(Box::new(closure)),
463463
cxx_qt::ConnectionType::AutoConnection,
@@ -478,7 +478,7 @@ mod tests {
478478
parse_quote! {
479479
impl cxx_qt::signalhandler::CxxQtSignalHandlerClosure for MyObjectCxxQtSignalClosureopaquePropertyChanged {
480480
type Id = cxx::type_id!("::rust::cxxqtgen1::MyObjectCxxQtSignalHandleropaquePropertyChanged");
481-
type FnType = dyn FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + Send;
481+
type FnType<'a> = dyn FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send;
482482
}
483483
},
484484
);
@@ -530,7 +530,7 @@ mod tests {
530530
unsafe extern "C++" {
531531
#[doc(hidden)]
532532
#[namespace = "rust::cxxqtgen1"]
533-
type MyObjectCxxQtSignalHandlerunsafePropertyChanged = cxx_qt::signalhandler::CxxQtSignalHandler<super::MyObjectCxxQtSignalClosureunsafePropertyChanged>;
533+
type MyObjectCxxQtSignalHandlerunsafePropertyChanged<'a> = cxx_qt::signalhandler::CxxQtSignalHandler<'a, super::MyObjectCxxQtSignalClosureunsafePropertyChanged>;
534534

535535
#[doc(hidden)]
536536
#[namespace = "rust::cxxqtgen1"]
@@ -560,9 +560,9 @@ mod tests {
560560
#[doc = "Connect the given function pointer to the signal "]
561561
#[doc = "unsafePropertyChanged"]
562562
#[doc = ", so that when the signal is emitted the function pointer is executed."]
563-
pub fn connect_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard
563+
pub fn connect_unsafe_property_changed<'a, F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QScopedMetaObjectConnectionGuard<'a>
564564
{
565-
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_unsafe_property_changed(
565+
cxx_qt::QScopedMetaObjectConnectionGuard::from(qobject::MyObject_connect_unsafe_property_changed(
566566
self,
567567
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosureunsafePropertyChanged>::new(Box::new(closure)),
568568
conn_type,
@@ -580,9 +580,9 @@ mod tests {
580580
#[doc = ", so that when the signal is emitted the function pointer is executed."]
581581
#[doc = "\n"]
582582
#[doc = "Note that this method uses a AutoConnection connection type."]
583-
pub fn on_unsafe_property_changed<F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'static + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QMetaObjectConnectionGuard
583+
pub fn on_unsafe_property_changed<'a, F: FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send>(self: core::pin::Pin<&mut qobject::MyObject>, closure: F) -> cxx_qt::QScopedMetaObjectConnectionGuard<'a>
584584
{
585-
cxx_qt::QMetaObjectConnectionGuard::from(qobject::MyObject_connect_unsafe_property_changed(
585+
cxx_qt::QScopedMetaObjectConnectionGuard::from(qobject::MyObject_connect_unsafe_property_changed(
586586
self,
587587
cxx_qt::signalhandler::CxxQtSignalHandler::<MyObjectCxxQtSignalClosureunsafePropertyChanged>::new(Box::new(closure)),
588588
cxx_qt::ConnectionType::AutoConnection,
@@ -603,7 +603,7 @@ mod tests {
603603
parse_quote! {
604604
impl cxx_qt::signalhandler::CxxQtSignalHandlerClosure for MyObjectCxxQtSignalClosureunsafePropertyChanged {
605605
type Id = cxx::type_id!("::rust::cxxqtgen1::MyObjectCxxQtSignalHandlerunsafePropertyChanged");
606-
type FnType = dyn FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + Send;
606+
type FnType<'a> = dyn FnMut(core::pin::Pin<&mut qobject::MyObject>, ) + 'a + Send;
607607
}
608608
},
609609
);

0 commit comments

Comments
 (0)