Results 1 to 10 of 10

Thread: How to use cmath.h with Qt OpenSource and minGW?

  1. #1
    Join Date
    Feb 2006
    Location
    Bella Vista, AR
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use cmath.h with Qt OpenSource and minGW?

    I'm using Qt 4.1.0 Open Source on Windows XP and haven't been able to use the fmod() function from within a dialog box method. A different post talks about adding options to the gcc command line, but I don't see how that applies to my config.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    In what way you "haven't been able" to use it? What did the compiler complain about?

  3. #3
    Join Date
    Feb 2006
    Location
    Bella Vista, AR
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    The error message was:
    fmod' undeclared (first use this function)

    At the beginning of the cpp file, I have this stmt
    #include <cmath.h>

    Thanks,

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    Try:
    Qt Code:
    1. #include <cmath>
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    Either:
    Qt Code:
    1. #include <math.h>
    2. a = fmod(x,y);
    To copy to clipboard, switch view to plain text mode 
    or:
    Qt Code:
    1. #include <cmath>
    2. a = ::fmod(x,y);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2006
    Location
    Bella Vista, AR
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    Great!
    I don't understand why including cmath.h doesn't work, but including cmath does, but for now I'm happy.

    Thanks.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    Quote Originally Posted by awbaker
    I don't understand why including cmath.h doesn't work, but including cmath does
    Because there is no such header as "cmath.h". All standard C++ headers don't have a customary ".h" extension.

  8. #8
    Join Date
    Feb 2006
    Location
    Bella Vista, AR
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    Sure enough - I checked the mingw include library and none of the files have the .h extension. The confusion factor comes with the Qt include library where all files DO have the .h extension.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    Quote Originally Posted by awbaker
    The confusion factor comes with the Qt include library where all files DO have the .h extension.
    Not quite, in Qt4 both versions are available, but the one without ".h" is preferred.

  10. #10
    Join Date
    Jan 2006
    Location
    New Zealand
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use cmath.h with Qt OpenSource and minGW?

    The C++ standard says that if you use #include <foo.h> that there is an actual file someplace called foo.h

    Using the notation #include <foo> makes no assumption about the storage of the "foo" library, it just guarantees the availability of the foo functions to your program.


    Also, the practical difference of <math.h> vs <cmath> is that the formers functions are automatically imported to the current namespace, while the latters aren't.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.