frontend: Use qobject_cast when casting QObjects#11784
frontend: Use qobject_cast when casting QObjects#11784cg2121 wants to merge 1 commit intoobsproject:masterfrom
Conversation
eb3f82d to
5582ea1
Compare
|
Converting to draft, as #11785 needs to be merged first. |
5582ea1 to
7808d32
Compare
7808d32 to
a9342f8
Compare
|
This PR now builds correctly |
3623034 to
c2398aa
Compare
PatTheMav
left a comment
There was a problem hiding this comment.
Overall I'm fine with this change, though it obviously touches a whole lot casts in the code that touch a whole lot of aspects of our frontend code, so this might be too late for the next version but should possibly merged after the next version is stabilised to give it some time to exist on the master branch.
@RytoEX WDYT?
I think this should be merged for 32.1, merge timing TBD. It does have a merge conflict though. |
c2398aa to
6789390
Compare
|
I've rebased this PR |
6789390 to
4b832ef
Compare
There was a problem hiding this comment.
Just looking at it, I think most of these should use static_cast instead of either dynamic_cast or qobject_cast. qobject_cast is better than dynamic_cast if you want the dynamic behavior (i.e. have the object be null if the cast fails), but if you already know/assume that the cast will succeed (and dont check for new_obj == nullptr), you can just use static_cast.
Also, original git commit authorship appears to have gotten lost, that should probably be reverted.
4b832ef to
7b82eec
Compare
Adjusted the PR for this, as well as removed a macro in the AutoConfig files that were casting the |
When casting between QObjects, qobject_cast should always be used for dynamic casts. This increases performance as there is no RTTI (Run Time Type Information) with qobject_cast, like there is with dynamic_cast. In other cases where we are sure or assume the cast is valid, use static_cast. Using reinterpret_cast is bad practice, as you should use it in very specific cases. Co-Authored-By: Clayton Groeneveld <19962531+cg2121@users.noreply.github.com>
7b82eec to
f6596c5
Compare
| OBSDataAutoRelease service_settings = obs_data_create(); | ||
|
|
||
| wiz->customServer = IsCustomService(); | ||
| autoConfig()->customServer = IsCustomService(); |
There was a problem hiding this comment.
Does it make sense to call autoConfig() here for every single line instead setting up a local variable that holds the reference to the widget?
It doesn't seem like it's expected for that object to change between all those function calls.
Description
When casting between QObjects, qobject_cast should always be used. This increases performance as there is no RTTI (Run Time Type Information) with qobject_cast, like there is with dynamic_cast.
Using reinterpret_cast is bad practice, as you should use it only in very specific cases.
Motivation and Context
Better code
How Has This Been Tested?
compiled and ran OBS
Types of changes
Checklist: