QML ReferenceError: Can't find variable



  • In QML I have defined some object:

    TestObject {
    model: myModel
    }

    In C++ I have set the model using setRootContext. This all works.

    Let's say in the configuration of the application there is an setting which causes the C++ myModel object not to be created and thus not binded to QML TestObject's model.

    (Ofcourse) now i get the "ReferenceError: Can' find variable: myModel.

    How to dynamicly set the model in QML?


  • Moderators

    Try:
    @
    TestObject {
    model: {
    if ((myModel != undefined) || (myModel != null))
    return myModel;
    else
    return 0;
    }
    @


Log in to reply
 

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