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 modify the data in the model and update the view when new data is received from external?
Forum Updated to NodeBB v4.3 + New Features

How to modify the data in the model and update the view when new data is received from external?

Scheduled Pinned Locked Moved Solved General and Desktop
76 Posts 4 Posters 51.3k 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.
  • ? A Former User

    @VRonin: Hi Ronin, thnx for the reply. Even without delegates it is not working. I believe it lies in model. I am updating a copy of the model but not the model.
    Here below, the model pointer is always in the old state, even after changing the values in my model class.

    void Delegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)
    

    For infor: I have hosted the project in Github: https://github.com/vinayrajputh/qtmodelview

    VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #66

    @VInay123 said in How to modify the data in the model and update the view when new data is received from external?:

    For infor: I have hosted the project in Github: https://github.com/vinayrajputh/qtmodelview

    Would have been nice if it compiled. Can you upload the ui and json file too?

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    ? 1 Reply Last reply
    1
    • VRoninV VRonin

      @VInay123 said in How to modify the data in the model and update the view when new data is received from external?:

      For infor: I have hosted the project in Github: https://github.com/vinayrajputh/qtmodelview

      Would have been nice if it compiled. Can you upload the ui and json file too?

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #67

      @VRonin : Done.

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #68

        I'm concentrating on the model only at the moment but it works perfectly for me.
        The only thing that I would flag is that the json that you provided has all "ReadOnly": true so it won't allow changes unless you change that to false.

        Could you try this fork and tell me what is that you expect to happen that is not happening?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        ? 1 Reply Last reply
        0
        • VRoninV VRonin

          I'm concentrating on the model only at the moment but it works perfectly for me.
          The only thing that I would flag is that the json that you provided has all "ReadOnly": true so it won't allow changes unless you change that to false.

          Could you try this fork and tell me what is that you expect to happen that is not happening?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #69

          @VRonin: Now there is a function with following signature

          void ScenarioPropertiesModel::onRefreshRoadInfo(const NewData& roadInfo) {}
          

          Now i would ask you to set the model data (properties) to the new values present in roadInfo variable(or to a random number) in the above function and display it in the view.

          My usecase is that, i will have a street and when user clicks on the street onRefreshRoadInfo will be called with the values which are actually coordinates and these i want to show.

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #70

            So you are confirming that, so far, the fork above is behaving correctly?

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            ? 1 Reply Last reply
            0
            • VRoninV VRonin

              So you are confirming that, so far, the fork above is behaving correctly?

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #71

              @VRonin : Yes, it works correctly. :)

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #72

                Could you check the same fork now and see if onRefreshRoadInfo does what you expect?

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                ? 1 Reply Last reply
                0
                • VRoninV VRonin

                  Could you check the same fork now and see if onRefreshRoadInfo does what you expect?

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by A Former User
                  #73

                  @VRonin : Hi Ronin, i checked your fork and it is working exactly as i need. So i tried to copy the code in my implementation and sadly it is not working, i even commented out the delegates. Could you please implement the ur logic in my code and see if you can make it work? I mean use the ui and view class. May be something is buggy in my view class? But there is nothing much in the view class too.

                  ------Update--------
                  I tried to use your main function with my implementation as below so that my view class is used. But turns out the implementation does not work.

                      QApplication a(argc, argv);
                      //ScenarioPropertiesModel model;
                      //QTreeView w;
                      //w.setModel(&model);
                      //w.show();
                      PropertyEditorView view;// model creation and setting done in class constructor
                   //   QPushButton sendRefreshRoadInfoButton("Refresh //Road Info");
                  //    sendRefreshRoadInfoButton.show();
                      //QObject::connect(&sendRefreshRoadInfoButton,&QPushB//utton::clicked,&model,&ScenarioPropertiesModel::onRe//freshRoadInfo); i use my own signal and slot
                      return a.exec();~~
                  

                  When i modified the main as below it is working.

                      QApplication a(argc, argv);
                      ScenarioPropertiesModel model;
                      PropertyEditorView w;
                      w.ui_->treeView->setModel(&model); // removed setting from PropertyEditorView constructor as we set here
                      w.show();
                      QPushButton sendRefreshRoadInfoButton("Refresh Road Info");
                      sendRefreshRoadInfoButton.show();
                      QObject::connect(&sendRefreshRoadInfoButton,&QPushButton::clicked,&model,&ScenarioPropertiesModel::onRefreshRoadInfo); 
                      return a.exec();
                  

                  Do you see any reason for this behavior.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #74

                    Because on your first version of the code you are not connecting to the model you have in your PropertyEditorView but the one you declared above. On a side note, that can't compile since you commented out your model declaration.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    ? 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Because on your first version of the code you are not connecting to the model you have in your PropertyEditorView but the one you declared above. On a side note, that can't compile since you commented out your model declaration.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #75
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by A Former User
                        #76

                        @SGaist @JonB @VRonin : So i took a deep breathe and tried to implement my code from scratch using @VRonin solution i.e. his latest fork https://github.com/VSRonin/qtmodelview.
                        Now my code is working :). This was the piece of line which helped me:

                            const QModelIndex parentIdx = index(0, 0);
                            const QModelIndex xValueIndex = index(0, 1, parentIdx);
                            setData(xValueIndex, 2.55);
                        

                        Additionally deep inside my code i had two pointers to my view which was also the cause for not showing the new values. The thread can be closed. I have a request @VRonin if he could take out the link to the code as it is a part of commercial project. Thank you everyone for your help, especially @VRonin.

                        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