-
Notifications
You must be signed in to change notification settings - Fork 82
Add a lifetime parameter to QMetaObjectConnectionGuard #1263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1263 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 73 73
Lines 12634 12634
=========================================
Hits 12634 12634 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hi @jnbooth, that sounds like a nice restriction to lift. IMO, the Can you try turning type QMetaObjetConnectionGuard = QScopedMetaObjectConnectionGuard<'static>; And then rename the old QMetaObjectConnectionGuard to QScopedMetaObjectConnectionGuard (or another name if you have a better idea). That should allow us to keep backwards compatibility. |
Hi, this mostly looks good, but @ahayzen-kdab and I just discussed whether there's any safety concerns we need to think about here. We found that this can probably introduce UB if the QScopedMetaObjectConnectionGuard is One way to solve this would be to make
As any pointer member type will make it no longer Send and Sync. |
I don't follow how that would result in UB, but I will take your word for it! |
Instead of requiring
'static
closures, connection signal handlers now accept lifetime parameters:This makes it possible to attach callbacks to signals that use scoped variables. Only
QMetaObjectConnectionGuard<'static>
can use.release()
, so the Drop implementation will ensure all other closures are disconnected once their lifetimes have expired.