Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is there any way to refresh/update a Context Property
Forum Updated to NodeBB v4.3 + New Features

Is there any way to refresh/update a Context Property

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    muzo
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        muzo
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved