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. Suppression of Implicit Conversion warnings
Forum Update on Monday, May 27th 2025

Suppression of Implicit Conversion warnings

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 4.9k Views
  • 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.
  • H Offline
    H Offline
    Hoyt
    wrote on last edited by
    #1

    I am running the current version of QtCreator on a Mac with the current version of Xcode.

    When I compile a program with the following line,

     int x = round(1.1);
    

    I receive a warning that states:

    "implicit conversion turns floating-point number to integer; 'double' to 'int'"

    How may I suppress such warnings?

    Thank you.

    Hoyt

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about using std::rint ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • H Offline
        H Offline
        Hoyt
        wrote on last edited by
        #3

        SGaist,

        The line

         x = std::rint(1.1);
        

        generates the same warning.

         "implicit conversion turns floating-point number into integer: 'double' to 'int'"
        

        I would like to turn off all "implicit conversion" warnings.

        Hoyt

        mrjjM 1 Reply Last reply
        0
        • H Hoyt

          SGaist,

          The line

           x = std::rint(1.1);
          

          generates the same warning.

           "implicit conversion turns floating-point number into integer: 'double' to 'int'"
          

          I would like to turn off all "implicit conversion" warnings.

          Hoyt

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Hoyt
          Hi
          Why not use
          std::lround(); ( Lround)
          If you want to round to nearest int.

          Google says you can hide these warnings you can switch “implicit conversion to 32 bit type” to no in your build settings. Might only affect other converts and not double to int truncating.
          Not that i recommend it as it will also hide the cases where it does matter :)

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hoyt
            wrote on last edited by
            #5

            mrjj,

            I receive another implicit conversion with std::lround()

            I can solve the problem by using static_cast<int> . I guess that I will utilize casting to eliminate the warnings.

            Hoyt

            mrjjM 1 Reply Last reply
            0
            • H Hoyt

              mrjj,

              I receive another implicit conversion with std::lround()

              I can solve the problem by using static_cast<int> . I guess that I will utilize casting to eliminate the warnings.

              Hoyt

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Hoyt
              Hi
              Ok which complication ?
              (just to know)
              yes, you can cast it and it should accept that.
              I just thought you wanted to round the value not cap it.
              so 1.0 and 1.9 both be 1.

              1 Reply Last reply
              1
              • J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @Hoyt
                you should combine static_cast<int> and round, otherwise you'll run into floating point issues. Remember:

                static_cast<int>(0.8 * 10) = 7  //!!! 
                
                int i = static_cast<int>(round(value));
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1

                • Login

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