Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Math functions/constants in QML code: i.e. M_PI or sin/cos/tg

Math functions/constants in QML code: i.e. M_PI or sin/cos/tg

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 4.7k 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.
  • B Offline
    B Offline
    biskero
    wrote on last edited by
    #1

    Hello,

    I am trying to use math functions and constants within my QML code but I am getting an error:

    ReferenceError: M_PI is not defined.

    I included the #include <QtMath> into main.cpp but it looks like is not enough to see the functions in my QML code.
    How do I include it in QML ?
    thx

    J.HilkJ 1 Reply Last reply
    0
    • B biskero

      Hello,

      I am trying to use math functions and constants within my QML code but I am getting an error:

      ReferenceError: M_PI is not defined.

      I included the #include <QtMath> into main.cpp but it looks like is not enough to see the functions in my QML code.
      How do I include it in QML ?
      thx

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @biskero
      QML uses JavaScript for that
      for pi you simply write Math.PI

      btw, what you include in cpp has little to no influence for qml


      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
      2
      • B Offline
        B Offline
        biskero
        wrote on last edited by
        #3

        @J.Hilk said in Math functions/constants in QML code: i.e. M_PI or sin/cos/tg:

        Math

        So I need to pre-pend Math. to any Math function I use like sqrt/sin/cos/tan, any link?
        thx!

        aha_1980A 1 Reply Last reply
        0
        • B biskero

          @J.Hilk said in Math functions/constants in QML code: i.e. M_PI or sin/cos/tg:

          Math

          So I need to pre-pend Math. to any Math function I use like sqrt/sin/cos/tan, any link?
          thx!

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @biskero please see here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

          Qt has to stay free or it will die.

          1 Reply Last reply
          3

          • Login

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