Is there any way to refresh/update a Context Property



  • I have a QVariantMap instance and im passing it as a Context Property by
    @
    QVariantMap theMap;

    //code block 1

    viewer.rootContext()->setContextProperty("theMap", theMap);

    //code block 2
    @

    if i populate theMap at code block 1 i can see changes in QML side but if i do it in code block 2 the changes will no be occur in QML.

    My question is how can i update theMap after passing it as a ContextProperty.
    Feel free to suggest different approaches :)


  • Moderators

    The property is copied when you assign it.

    You should use a QObject instead, and define your data as Q_PROPERTY with NOTIFY signals, so that QML engine can know it has changed.



  • thx for answer. i solved this problem by setting the context property each time i update it.

    i mean
    @
    //helper class..
    void onMapUpdated()
    {
    this->_viewer->rootContext()->setContextProperty("theMap", theMap);
    }
    @

    • i passed the ApplciaitonViewer object as a paramter to the helper class constructor.

    it is working now. but im worried about its drawbacks. what can they be? do u have an opinion?


Log in to reply
 

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