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. Passing model data from delegate Loader to component in TableView object.
Forum Updated to NodeBB v4.3 + New Features

Passing model data from delegate Loader to component in TableView object.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
12 Posts 4 Posters 807 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.
  • J Offline
    J Offline
    jebediahcrunk
    wrote on last edited by
    #3

    Hi thanks,

    Unfortunately that still gives
    ReferenceError: model is not defined

    JoeCFDJ 1 Reply Last reply
    0
    • J jebediahcrunk

      Hi thanks,

      Unfortunately that still gives
      ReferenceError: model is not defined

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #4

      @jebediahcrunk Is } for GateIcon missing?

                      Component {
                          id: gateDelegate
                          GateIcon {
                              gateType : delegateLoader.type
             
                              implicitWidth: 40
                              implicitHeight: 40
                          }
                    }
      
      1 Reply Last reply
      0
      • J Offline
        J Offline
        jebediahcrunk
        wrote on last edited by
        #5

        Sorry, i took some parts out of my actual code to make it a bit more readable so accidentally deleted that in the process. That is not the issue though.

        JoeCFDJ 1 Reply Last reply
        0
        • J jebediahcrunk

          Sorry, i took some parts out of my actual code to make it a bit more readable so accidentally deleted that in the process. That is not the issue though.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #6

          @jebediahcrunk I did similar thing.
          model is visible for component and gateType : model.gateType should work.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bob64
            wrote on last edited by Bob64
            #7

            I do something like this in my application. Loader introduces some not necessarily intuitive behaviour about scoping of properties. I think you have accounted for this by introducing your type property at the loader level as a means of passing the model's gateType to your loaded component.

            However, in my code at least, I do not refer to the loader in my loaded component (I do not even give the loader an ID). Instead I simply access the properties that are defined at the loader level because these now exist in the scope of the loaded component.

            In your case, that would mean changing to this:

            GateIcon {
                gateType : type // this is the property defined in `Loader`
                ...
            }
            
            1 Reply Last reply
            0
            • GrecKoG Offline
              GrecKoG Offline
              GrecKo
              Qt Champions 2018
              wrote on last edited by
              #8

              @jebediahcrunk : is the Loader needed here?

              What is discussed here is sharing data via context properties, a system that is not recommended anymore.

              B 1 Reply Last reply
              0
              • GrecKoG GrecKo

                @jebediahcrunk : is the Loader needed here?

                What is discussed here is sharing data via context properties, a system that is not recommended anymore.

                B Offline
                B Offline
                Bob64
                wrote on last edited by
                #9

                @GrecKo said in Passing model data from delegate Loader to component in TableView object.:

                @jebediahcrunk : is the Loader needed here?

                What is discussed here is sharing data via context properties, a system that is not recommended anymore.

                That's interesting. What would be recommended now?

                I use Loader for a case where I have heterogeneous components shown in a ListView. I am aware of DelegateChooser as another way of doing this in theory, but I saw some weird behaviour when I tried to use it. I forget the details - I need to have another go sometime - but things like properties such as the model index that should have been accessible were sometimes not available in the delegates. Also, the documentation is unclear as to whether it should even be expected to work with a ListView. (Is ListView "internally based on a DelegateModel"? How am I supposed to know this?)

                1 Reply Last reply
                0
                • GrecKoG Offline
                  GrecKoG Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on last edited by
                  #10

                  That's interesting. What would be recommended now?

                  DelegateChooser

                  Is ListView "internally based on a DelegateModel"? How am I supposed to know this?

                  Yes. Good question 😬 reading the code can answer that but that's hardly practical.
                  In practice view taking QAbstractItemModel but also QList, JS arrays are based on DelegateModel.
                  This is the case for ListView, TableView, Repeater, ...

                  B 1 Reply Last reply
                  1
                  • GrecKoG GrecKo

                    That's interesting. What would be recommended now?

                    DelegateChooser

                    Is ListView "internally based on a DelegateModel"? How am I supposed to know this?

                    Yes. Good question 😬 reading the code can answer that but that's hardly practical.
                    In practice view taking QAbstractItemModel but also QList, JS arrays are based on DelegateModel.
                    This is the case for ListView, TableView, Repeater, ...

                    B Offline
                    B Offline
                    Bob64
                    wrote on last edited by
                    #11

                    @GrecKo OK, thanks. I did actually want to switch to DelegateChooser so I will try it again. And good to know about its applicability.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jebediahcrunk
                      wrote on last edited by
                      #12

                      @Bob64 Thank you, just using 'type' worked! I knew it would be something simple like this. And @GrecKo thanks for the tip, that looks like a better solution so ill definitely look into it.

                      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