Nominate our 2022 Qt Champions!

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

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

Log in to reply