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. SetContextProperty
Qt 6.11 is out! See what's new in the release blog

SetContextProperty

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 595 Views 2 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.
  • A Offline
    A Offline
    Anita
    wrote on last edited by Anita
    #1

    I have to change the value of setContextProperty dynamically.

    For example:

    I have the following code:
    engine.rootContext()->setContextProperty("TestingProperty",testValue);
    dynamically i need to change the value of testValue, will that be reflected on TestingProperty?

    Edit1:
    I found a solution to this. I am storing the Address of the QQmlApplicationEngine , and reassigning the contextproperty again when i need a dynamic change. Is that the right way to do it?

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

      The usual approach is to pass a QObject subclass as context property. Whatever values you need to update can then easily be managed via Q_PROPERTY and QML will pick up those changes automatically.

      (Z(:^

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Anita
        wrote on last edited by
        #3

        Hi sierdzio,

        I have tried with a method of having the stroring the engine address in a QQmlApplictaionEngine variable into a local variable of the class(ApplicationEngine).

        and when i have to change the value dynamically, i reassign the value as :
        ApplicationEngine->rootContext()->setContextProperty("TestingProperty",testValue_new);

        It works . But is there any problem in this method?

        sierdzioS 1 Reply Last reply
        0
        • A Anita

          Hi sierdzio,

          I have tried with a method of having the stroring the engine address in a QQmlApplictaionEngine variable into a local variable of the class(ApplicationEngine).

          and when i have to change the value dynamically, i reassign the value as :
          ApplicationEngine->rootContext()->setContextProperty("TestingProperty",testValue_new);

          It works . But is there any problem in this method?

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @Anita said in SetContextProperty:

          It works . But is there any problem in this method?

          Sounds good to me.

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anita
            wrote on last edited by
            #5

            Thank You.
            Thank you for the other solution as well.

            1 Reply Last reply
            1

            • Login

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