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. How to update QTreeView?

How to update QTreeView?

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 4.0k 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.
  • ahsan737A Offline
    ahsan737A Offline
    ahsan737
    wrote on last edited by
    #1

    Greetings,
    I am building the QTreeView model from CSV data, How can I update/repopulate view if file data is changed/updated?
    Looking forward to the considerate reply.

    Best regards,
    Ahsan

    JonBJ 1 Reply Last reply
    0
    • MucipM Offline
      MucipM Offline
      Mucip
      wrote on last edited by
      #2

      Hi,
      You may celar all data in the tree and reload it from csv file.

      Regards,
      Mucip:)

      1 Reply Last reply
      0
      • ahsan737A ahsan737

        Greetings,
        I am building the QTreeView model from CSV data, How can I update/repopulate view if file data is changed/updated?
        Looking forward to the considerate reply.

        Best regards,
        Ahsan

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @ahsan737
        If you repopulate (or regenerate) the model by reloading the file, the QTreeView will see that and refresh for you, without you needing to do anything else.

        You can also recognise that an external file has been modified via https://doc.qt.io/qt-5/qfilesystemwatcher.html.

        ahsan737A 1 Reply Last reply
        1
        • JonBJ JonB

          @ahsan737
          If you repopulate (or regenerate) the model by reloading the file, the QTreeView will see that and refresh for you, without you needing to do anything else.

          You can also recognise that an external file has been modified via https://doc.qt.io/qt-5/qfilesystemwatcher.html.

          ahsan737A Offline
          ahsan737A Offline
          ahsan737
          wrote on last edited by
          #4

          @JonB if I regenerate then it doubles the information.

          MucipM 1 Reply Last reply
          0
          • ahsan737A ahsan737

            @JonB if I regenerate then it doubles the information.

            MucipM Offline
            MucipM Offline
            Mucip
            wrote on last edited by
            #5

            @ahsan737 ,
            That's why I said you need to clear all list first. :)

            Regards,
            Mucip:)

            1 Reply Last reply
            0
            • JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @ahsan737 , @Mucip
              Sorry, I don't understand these two posts. If your QTreeView is bound to a model, it shows what is in that model. It does not "retain previous stuff". Where do you get "doubles the information" or "need to clear it first" from? What are you talking about clearing, there is no QTreeView::clear()? Obviously "regenerate the model" does not mean "append to whatever is presently there".

              J.HilkJ MucipM 2 Replies Last reply
              0
              • JonBJ JonB

                @ahsan737 , @Mucip
                Sorry, I don't understand these two posts. If your QTreeView is bound to a model, it shows what is in that model. It does not "retain previous stuff". Where do you get "doubles the information" or "need to clear it first" from? What are you talking about clearing, there is no QTreeView::clear()? Obviously "regenerate the model" does not mean "append to whatever is presently there".

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @JonB

                I think the OP did not use a proper model but rather the (in)famous setItemWidget function...


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                JonBJ ahsan737A 2 Replies Last reply
                0
                • J.HilkJ J.Hilk

                  @JonB

                  I think the OP did not use a proper model but rather the (in)famous setItemWidget function...

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @J-Hilk
                  @ahsan737 wrote:

                  I am building the QTreeView model from CSV data,

                  Clearly your powers of guessing/interpreting are better than mine! ;)

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @ahsan737 , @Mucip
                    Sorry, I don't understand these two posts. If your QTreeView is bound to a model, it shows what is in that model. It does not "retain previous stuff". Where do you get "doubles the information" or "need to clear it first" from? What are you talking about clearing, there is no QTreeView::clear()? Obviously "regenerate the model" does not mean "append to whatever is presently there".

                    MucipM Offline
                    MucipM Offline
                    Mucip
                    wrote on last edited by
                    #9

                    @JonB ,
                    I mean;
                    ui->someTreeWidget->clear();

                    Regards,
                    Mucip:)

                    JonBJ 1 Reply Last reply
                    0
                    • MucipM Mucip

                      @JonB ,
                      I mean;
                      ui->someTreeWidget->clear();

                      Regards,
                      Mucip:)

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @Mucip
                      OK, but that is QTreeWidget::clear(), and the OP's question is "How to update QTreeView", QTreeWidget has never been mentioned. I'm sure he would ask about QTreeWidget not just QTreeView if that's what he wants to know about. Ho-hum.

                      1 Reply Last reply
                      0
                      • J.HilkJ J.Hilk

                        @JonB

                        I think the OP did not use a proper model but rather the (in)famous setItemWidget function...

                        ahsan737A Offline
                        ahsan737A Offline
                        ahsan737
                        wrote on last edited by
                        #11

                        @J-Hilk I am creating the QTreeView model using this method:

                        //--------------------Tree View Model--------------------------
                        QStandardItemModel *model=new QStandardItemModel (this);
                        rootItem=model->invisibleRootItem();
                        
                        QStandardItem *TitleItem=new QStandardItem ("\n"+Title_line.at(i)+"\n"+second_line.at(i)+"\n"+third_line.at(i));
                        
                        TitleItem->setIcon(QIcon(":/img/img/saved_data.jpg.png"));
                        
                        //defining tree structure
                        rootItem->appendRow(TitleItem);
                        ui->treeView->setModel(model);
                        
                        JonBJ 1 Reply Last reply
                        0
                        • ahsan737A ahsan737

                          @J-Hilk I am creating the QTreeView model using this method:

                          //--------------------Tree View Model--------------------------
                          QStandardItemModel *model=new QStandardItemModel (this);
                          rootItem=model->invisibleRootItem();
                          
                          QStandardItem *TitleItem=new QStandardItem ("\n"+Title_line.at(i)+"\n"+second_line.at(i)+"\n"+third_line.at(i));
                          
                          TitleItem->setIcon(QIcon(":/img/img/saved_data.jpg.png"));
                          
                          //defining tree structure
                          rootItem->appendRow(TitleItem);
                          ui->treeView->setModel(model);
                          
                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @ahsan737
                          I did say earlier to answer both your questions:

                          @ahsan737
                          If you repopulate (or regenerate) the model by reloading the file, the QTreeView will see that and refresh for you, without you needing to do anything else.
                          .
                          You can also recognise that an external file has been modified via https://doc.qt.io/qt-5/qfilesystemwatcher.html.

                          You said:

                          @JonB if I regenerate then it doubles the information.

                          But it should not do that. So what did you do?

                          ahsan737A 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @ahsan737
                            I did say earlier to answer both your questions:

                            @ahsan737
                            If you repopulate (or regenerate) the model by reloading the file, the QTreeView will see that and refresh for you, without you needing to do anything else.
                            .
                            You can also recognise that an external file has been modified via https://doc.qt.io/qt-5/qfilesystemwatcher.html.

                            You said:

                            @JonB if I regenerate then it doubles the information.

                            But it should not do that. So what did you do?

                            ahsan737A Offline
                            ahsan737A Offline
                            ahsan737
                            wrote on last edited by
                            #13

                            @JonB thank you for the considerate response, can you please help with a sample code then it will be easy for me to understand, I am not good with Qt.

                            JonBJ 1 Reply Last reply
                            0
                            • ahsan737A ahsan737

                              @JonB thank you for the considerate response, can you please help with a sample code then it will be easy for me to understand, I am not good with Qt.

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #14

                              @ahsan737
                              You should show what code you have used to "regenerate then it doubles the information".

                              ahsan737A 2 Replies Last reply
                              2
                              • JonBJ JonB

                                @ahsan737
                                You should show what code you have used to "regenerate then it doubles the information".

                                ahsan737A Offline
                                ahsan737A Offline
                                ahsan737
                                wrote on last edited by
                                #15
                                This post is deleted!
                                1 Reply Last reply
                                0
                                • JonBJ JonB

                                  @ahsan737
                                  You should show what code you have used to "regenerate then it doubles the information".

                                  ahsan737A Offline
                                  ahsan737A Offline
                                  ahsan737
                                  wrote on last edited by
                                  #16

                                  @JonB I have done that successfully, thank you for guidance. I was only clearing model and rootItem data but forgot to reset variable values.

                                  JonBJ 1 Reply Last reply
                                  0
                                  • ahsan737A ahsan737

                                    @JonB I have done that successfully, thank you for guidance. I was only clearing model and rootItem data but forgot to reset variable values.

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by
                                    #17

                                    @ahsan737
                                    This is why it's always good to show code :)

                                    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