-
Notifications
You must be signed in to change notification settings - Fork 82
Remove unused self parameters in Q*Application static methods #1216
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 #1216 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 73 73
Lines 12612 12612
=========================================
Hits 12612 12612 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sorry for not thinking of this earlier, but I just realized we may have a safety issue with these methods (which may be why we made them "members" initially). Some of them seem to be not thread-safe! So they are effectively only safe-to-call from a single thread (presumably the "main thread") The Qt docs also state that e.g. only one So the way these could be made safe is by keeping them as member functions and enforcing in the constructor that only a single QGuiApplication can actually be constructed (and disabling Send+Sync). I'm also open to other suggestions, especially as keeping member functions is inconvenient. |
I believe this is true of all GUI operations, not just the ones related to
EDIT: It could be possible to throw a runtime error if code executes outside the main thread. That seems like a method of last resort, though. |
Hm, with this kind of design by Qt, I think we may not get around doing runtime checks tbh. In general, we should make sure that the objects that need to be used from the main thread are not There is a method since Qt 6.8 that we can use to check this: For the static functions in Unfortunately it uses some private API internally, so it would probably be hard to backport for Qt5 and Qt 6.7-. More ideas are certainly welcome... @ahayzen-kdab @jnbooth ? |
@LeonMatthesKDAB yup, this is all quite fun, another one of the reasons why avoiding having GUI code in the Rust side is useful and just exposing models :-) For the actual Q*Application classes you can only have one instance of them and they all inherit from QCoreApplication and note as the docs of the isMainThread state So for finding out if you are the main thread after creating the application could you not do |
Hm, I know that at least on MacOS, any event processing has to actually happen on the main thread, (e.g. the one that executes It's possible that just checking the instances thread is good enough though. |
I've added (unused)
The Q*Application structs do not implement
Does it? I don't see that in the documentation. |
Resolves #1205.
Note: This PR contains breaking changes.