Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why would anyone write int(qRound(x)) ?
Qt 6.11 is out! See what's new in the release blog

Why would anyone write int(qRound(x)) ?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 540 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bart_Vandewoestyne
    wrote on last edited by
    #1

    In the legacy codebase I'm working on (dating from Qt 4.8.7 or earlier) I often encounter statements similar to the following:

    int y = int(qRound(x));
    

    Looking at the Qt 5 documentation for qRound at https://doc.qt.io/qt-5/qtglobal.html I see that qRound's return type is int. So why on earth would anyone use int(qRound(x)) instead of just qRound(x)? Would there be a good reason for this? Maybe historically? Has qRound always had a return type of int? I'm planning to refactor this and remove the int(.), but first would like to get a second opinion on whether there are pitfalls that I'm not thinking of...

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      it has always been an int since before the release of Qt 4.8.7
      I think that cast is there as a refuse from the STL (std::round(double) returns a double) and your compiler optimises it away in any case

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      B 1 Reply Last reply
      5
      • VRoninV VRonin

        it has always been an int since before the release of Qt 4.8.7
        I think that cast is there as a refuse from the STL (std::round(double) returns a double) and your compiler optimises it away in any case

        B Offline
        B Offline
        Bart_Vandewoestyne
        wrote on last edited by
        #3

        Thanks for confirming. I'll remove the int(.) and go on with my life ;-)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved