-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
frontend: Enable Qt strict mode #12567
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: master
Are you sure you want to change the base?
Conversation
SetComboByName, SetComboByValue and SetInvalidValue all pass their parameters to Qt functions which only take QStrings. As a consequence, we have cases we'd convert a QString to a const char* to call these functions, only for the functions to implicitly convert them back into QStrings. We can avoid this by passing QStrings directly. In cases where we did actually pass const chars, the (implicit) conversion now just takes place earlier.
If calling |
I'm not sure what you mean, all |
Things like |
Ah, that's what you mean. I'd argue technically that's not exactly in scope for this change but there's only one instance of that that doesn't use the contextless connect, so I guess I'll add it to this PR. |
6a296f8
to
1f87d4d
Compare
Qt strict mode disables APIs deemed "'suboptimal' or 'dangerous'" [1] and "clearly undesirable" [2] by Qt that will be removed in the long term. Usages of the APIs in OBS have been removed in the previous commits, and by setting this flag we keep ourselves from using them again. The versioning works in a way where e.g. a new addition to this in 6.9 would only be disabled if at least 0x060900 is set. By setting 0xFF0000, we're effectively disabling any APIs that are deemed to be bad in any future Qt version (up to 255). While this could lead to OBS not being buildable against bleeding edge Qt, it also means that it will be noticed early. Should the disabled API turn out to be too complex to remove, the value can be downgraded to the last working one then. [1] qt/qtbase@3a6c8e0 [2] qt/qtbase@f9163ae
Tested on Ubuntu 24.04, compiles without issues, played around with every different bit of UI I could think of, found no issues. |
Will probably target this for 32.1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, I'd prefer if we could replace use of QT_TO_UTF8
with the explicit .toUtf8().constData()
call, particularly as some changed code uses that or constData()
already.
I'd probably also like to see a variant of QTStr
that accepts a QString
and a renaming of QTStr
itself as that function name is incredibly uninformative, but those two can wait for another PR.
lastErrorReason.clear(); | ||
const QByteArray url = YOUTUBE_LIVE_CHANNEL_URL "?part=snippet,contentDetails,statistics" | ||
"&mine=true"; | ||
const char *url = YOUTUBE_LIVE_CHANNEL_URL "?part=snippet,contentDetails,statistics" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use std::string_view
instead of raw char pointers in C++ (prefer C++ types over C types).
Notably string views can also be static constexpr
and either be resolved at compile time or (when reaching to their underlying character data via .data()
) become read accesses into the data region (no allocations).
I actually have a branch already to at least get rid of
Will change that. |
Great job, let's do that in a separate PR then. 💪🏻 |
Description
Enables Qt strict mode, and makes the changes needed in the codebase to do so.
Strict mode disables "a number of Qt APIs that are deemed suboptimal or dangerous" and that, while not yet officially deprecated, will be removed in the long term. This includes (but isn't limited to) the
foreach
macro, contextless connects (connect()
calls without a receiver), implicit conversions fromQByteArray
toconst char *
, and implicit conversions fromQString
toQUrl
.Motivation and Context
We have previously done cleanups on
foreach
(see #9662), and things like the contextless connect calls sometimes come up during PR reviews. As can be seen by the first commit, especially the implicitQByteArray
->const char *
conversions can cause unneeded back-and-forth conversions in some scenarios, not having them is actually advantageous as it reveals the conversions that are happening.Qt is also moving towards using strict mode themselves (see QTBUG-132327).
By fixing all of these occurrences and turning on strict mode, we prevent the dangerous APIs from being used again in the future.
How Has This Been Tested?
macOS 26.
The code compiles.
I tested in all cases that the connections are still hit, and that conversions still yield the correct results (yes, this took a while.)
Types of changes
Checklist: