Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Update data to QTreewidget every sec
Forum Updated to NodeBB v4.3 + New Features

Update data to QTreewidget every sec

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 3.1k 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.
  • saitejS Offline
    saitejS Offline
    saitej
    wrote on last edited by
    #1

    I want to update from a source after every sec. I have data but am unable to write the new data to the treewidget. Need some help to write the updateData() function.

    Header
    Source

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      What is the problem?
      What help do you need?
      Where does the data come from?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      saitejS 1 Reply Last reply
      0
      • jsulmJ jsulm

        What is the problem?
        What help do you need?
        Where does the data come from?

        saitejS Offline
        saitejS Offline
        saitej
        wrote on last edited by
        #3

        @jsulm
        I am getting the data from another class. i need to display this data. I am able display it the first time but its not autorefreshing so I put this timer and a slot updateData(). I need help in writing this function.

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What help do you need?
          Most simple solution: in updateData() you recreate the complete tree (delete all items and then add new items based on current data).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          saitejS 1 Reply Last reply
          1
          • jsulmJ jsulm

            What help do you need?
            Most simple solution: in updateData() you recreate the complete tree (delete all items and then add new items based on current data).

            saitejS Offline
            saitejS Offline
            saitej
            wrote on last edited by
            #5

            @jsulm
            I have done that but the text added by item1->setText(0,"data1"); is not getting deleted. I have used the following code to delete all the items.

            for(int i=0;i< ui->treeWidget->topLevelItemCount();++i){
                    qDeleteAll(ui->treeWidget->topLevelItem(i)->takeChildren());
            }
            
            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              hi
              Cant
              http://doc.qt.io/qt-5/qtreewidget.html#clear
              be used ?

              saitejS 1 Reply Last reply
              1
              • mrjjM mrjj

                hi
                Cant
                http://doc.qt.io/qt-5/qtreewidget.html#clear
                be used ?

                saitejS Offline
                saitejS Offline
                saitej
                wrote on last edited by
                #7

                @mrjj
                Ya it works but the parent item gets closed on every update.

                mrjjM 1 Reply Last reply
                0
                • saitejS saitej

                  @mrjj
                  Ya it works but the parent item gets closed on every update.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @saitej
                  No matter how you remove the items, it cannot
                  keep open/close status since you remove the items.

                  saitejS 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @saitej
                    No matter how you remove the items, it cannot
                    keep open/close status since you remove the items.

                    saitejS Offline
                    saitejS Offline
                    saitej
                    wrote on last edited by
                    #9

                    @mrjj
                    so is there a way to get back to the same status as before after the update ?

                    mrjjM 1 Reply Last reply
                    0
                    • saitejS saitej

                      @mrjj
                      so is there a way to get back to the same status as before after the update ?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @saitej
                      Hi, not as far as I know. not unless u save it yourself.

                      saitejS 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @saitej
                        Hi, not as far as I know. not unless u save it yourself.

                        saitejS Offline
                        saitejS Offline
                        saitej
                        wrote on last edited by
                        #11

                        @mrjj
                        ok !! Thanks :)

                        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