Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to make qml aware of changes happened in C++ side?
Qt 6.12 LTS is out! See what's new in the release blog

How to make qml aware of changes happened in C++ side?

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

    Hey,
    Imagine you have a Qvector of Qstring type and you put some names there something like :

    Qvector<QString> names;
    name.append("Sara");
    ...
    name.append("Caroline");
    name.append("Isabella");
    

    In qml you implement a repeater to show these names inside of some rectangles.What if you change one name of this vector from c++ side?How you can force repeater to repeat again and update the qml side to show new names?

    How many ways are exist for that and which one has better performance?

    raven-worxR 1 Reply Last reply
    0
    • AlienA Alien

      Hey,
      Imagine you have a Qvector of Qstring type and you put some names there something like :

      Qvector<QString> names;
      name.append("Sara");
      ...
      name.append("Caroline");
      name.append("Isabella");
      

      In qml you implement a repeater to show these names inside of some rectangles.What if you change one name of this vector from c++ side?How you can force repeater to repeat again and update the qml side to show new names?

      How many ways are exist for that and which one has better performance?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Alien
      I guess you are after a property binding.

      Thus you should define a custom type with a QStringList property. Make sure that the property has a NOTIFY signal and trigger this signal whenever the property changes.

      For example:

      Q_PROPERTY( QStringList myList READ getMyList WRITE setMyList NOTIFY myListChanged )
      

      Then trigger the myListChanged signal in the setMyList setter method.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      AlienA 1 Reply Last reply
      2
      • raven-worxR raven-worx

        @Alien
        I guess you are after a property binding.

        Thus you should define a custom type with a QStringList property. Make sure that the property has a NOTIFY signal and trigger this signal whenever the property changes.

        For example:

        Q_PROPERTY( QStringList myList READ getMyList WRITE setMyList NOTIFY myListChanged )
        

        Then trigger the myListChanged signal in the setMyList setter method.

        AlienA Offline
        AlienA Offline
        Alien
        wrote on last edited by
        #3

        Dear @raven-worx ,
        That's true one solution is using model of repeater like QStringList, QAbstractItemModel,etc but is there any other solution for that something that cause repaint in qml item therefor repeater force to repeat again and finally shows updated data on the screen?

        raven-worxR 1 Reply Last reply
        0
        • AlienA Alien

          Dear @raven-worx ,
          That's true one solution is using model of repeater like QStringList, QAbstractItemModel,etc but is there any other solution for that something that cause repaint in qml item therefor repeater force to repeat again and finally shows updated data on the screen?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @Alien
          why would it just need to be repainted?
          If the data has changed you should notify it as i said. Or in case of a QAbstractItemModel emit the dataChanged() signal

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          AlienA 1 Reply Last reply
          2
          • raven-worxR raven-worx

            @Alien
            why would it just need to be repainted?
            If the data has changed you should notify it as i said. Or in case of a QAbstractItemModel emit the dataChanged() signal

            AlienA Offline
            AlienA Offline
            Alien
            wrote on last edited by
            #5

            @raven-worx ,
            Thanks for your solution it seems that there is no need to repaint,Thank you.

            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
            • Unsolved