Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Javascript overwriting of prototype method leads to type error
Forum Updated to NodeBB v4.3 + New Features

Javascript overwriting of prototype method leads to type error

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 870 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.
  • M Offline
    M Offline
    mraalex
    wrote on 29 Jul 2014, 15:50 last edited by
    #1

    Hi,
    MCAddition is overwriting function protoype.getChallengeName from MC. But when I call the method in QML I can an error saying "TypeError: Type Error".

    What am I doing wrong?

    Alex

    ============== File MC.js ====================
    .pragma library

    Qt.include("../Common.js")

    function MC() {

    }

    MC.prototype.getChallengeName=function() {
    return "N";
    }

    ============== File MCAddition.js ====================
    .pragma library

    Qt.include("MC.js")

    MCAddition.prototype=new MC();
    MCAddition.prototype.constructor=MCAddition;

    function MCAddition() {

    }

    MCAddition.protoype.getChallengeName=function() {
    return "A";
    }

    ============== File main.qml ====================
    ...
    Button {
    id: button1
    x: 0
    y: 0
    width: parent.width/2
    height: parent.height/2
    text: "1"
    onClicked: {
    var MC=new MC.MCAddition();
    var challengeName=MC.getChallengeName();
    }
    }

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p3c0
      Moderators
      wrote on 30 Jul 2014, 05:50 last edited by
      #2

      Hi,

      Did you import the js file in QML ?
      Like for eg.
      @
      import "logic.js" as Logic
      @

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mraalex
        wrote on 30 Jul 2014, 06:29 last edited by
        #3

        Yes, import "MCAddition.js" as MC

        1 Reply Last reply
        0

        1/3

        29 Jul 2014, 15:50

        • Login

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