Javascript overwriting of prototype method leads to type error



  • 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();
    }
    }


  • Moderators

    Hi,

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



  • Yes, import "MCAddition.js" as MC


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.