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. Referencing QML objects from JS: ReferenceError: <model> is not defined [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Referencing QML objects from JS: ReferenceError: <model> is not defined [SOLVED]

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

    I'm in the process of porting a QtQuick 1.x app to 2.0 and got hung up on a very odd spot:

    [code]ReferenceError: productsModel is not defined[/code]

    The offending code is painfully simple:

    [code]
    import "binticketreport.js" as JS

    Rectangle {
    id: reportContainer
    width: 400
    height: 200

    ListModel {
        id: productsModel
    }
    
    Button {
        onClicked: {
            JS.binticketReport.scanSku();
        }
    }
    

    }
    [/code]

    and in the JS code:

    [code]
    Qt.include('otherscript.js');

    var binticketReport = {
    scanSku: function()
    {
    productsModel.append( { 'name': 'foo' } );
    }
    }
    [/code]

    Google and the forums haven't produced anything I could recognize as a solution.

    I've discovered it stems from the use of Qt.include("[removed]"); which appears to register within a blank rootContext.

    Changing these occurances to use .import "[removed]" as <ReferenceName> fixes the issue.

    I hope this helps others in their porting process.

    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