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

Javascript overwriting of prototype method leads to type error

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 951 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 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
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on 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 last edited by
        #3

        Yes, import "MCAddition.js" as MC

        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