Important: Please read the Qt Code of Conduct -

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

  • 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:

    import "binticketreport.js" as JS

    Rectangle {
    id: reportContainer
    width: 400
    height: 200

    ListModel {
        id: productsModel
    Button {
        onClicked: {


    and in the JS code:


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

    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.

Log in to reply