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:

    [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.


Log in to reply
 

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