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. QML Javascript help
Qt 6.11 is out! See what's new in the release blog

QML Javascript help

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 2.6k 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.
  • D Offline
    D Offline
    doforumda
    wrote on last edited by
    #1

    I am trying to integrate QML and Javscript following this link
    "Click Here":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativejavascript.html
    So when i import js file and then when i run it it displays this error
    @
    TypeError: Result of Expression 'Math.factorial' [undefined] is not a function.
    @

    here is the code
    QML
    @
    import Qt 4.7
    import "factorial.js" as Math

    Item {
    width: 200; height: 200
    MouseArea {
    anchors.fill: parent
    onClicked: console.log(Math.factorial(10))
    }
    }
    @

    here is factorial.js
    @
    function factorial(a) {
    a = parseInt(a);
    if (a <= 0)
    return 1;
    else
    return a * factorial(a - 1);
    }
    @

    what is the wrong here?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      baysmith
      wrote on last edited by
      #2

      Change Math to MyMath. The "as" name must be unique, but Math is a pre-existing name.

      Nokia Certified Qt Specialist.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        syrianzoro
        wrote on last edited by
        #3

        @import Qt 4.7
        import "factorial.js" as Math1

        Item {
        width: 200; height: 200
        MouseArea {
        anchors.fill: parent
        onClicked: console.log(Math1.factorial(10))

          }
        

        }
        @

        Qt is the future

        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