obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

frontend: Use qobject_cast when casting QObjects

Open cg2121 opened this issue 11 months ago • 4 comments

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

  • Bug fix (non-breaking change which fixes an issue) -->
  • Performance enhancement (non-breaking change which improves efficiency)

Checklist:

  • [x] My code has been run through clang-format.
  • [x] I have read the contributing document.
  • [x] My code is not on the master branch.
  • [x] The code has been tested.
  • [x] All commit messages are properly formatted and commits squashed where appropriate.
  • [x] I have included updates to all appropriate documentation.

cg2121 avatar Jan 28 '25 11:01 cg2121

Converting to draft, as #11785 needs to be merged first.

cg2121 avatar Jan 28 '25 12:01 cg2121

This PR now builds correctly

cg2121 avatar May 05 '25 18:05 cg2121

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.

RytoEX avatar Nov 19 '25 19:11 RytoEX

I've rebased this PR

Warchamp7 avatar Nov 27 '25 22:11 Warchamp7