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. accessing aggregates (QVector of a struct)
Forum Updated to NodeBB v4.3 + New Features

accessing aggregates (QVector of a struct)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
52 Posts 4 Posters 6.9k Views 4 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 2 Mar 2021, 23:03 last edited by
    #1

    Hi all -

    I'm in need of a bit of guidance here. I've collected some data that I need to represent in a QML screen. I've put the data into a QVector of this struct:

    struct BottleInfo {
        float volume;
        float amountNeeded;
        int position;
        std::string name;
        ReagentBottleType bottleType;
    };
    typedef QVector<BottleInfo> BottleList;
    

    but this is totally up to me -- I can store it another way if it makes QML access easier.

    The vector is small (currently known to be 16 elements).

    So:

    1. is this a good way to store data that needs to be QML-accessible?
    2. what is the syntax for accessing members of an element of a vector?

    Thanks...

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mzimmers
      wrote on 3 Mar 2021, 16:54 last edited by
      #2

      I'm trying to use this example:

      enum class ReagentBottleType;
      struct BottleData {
          Q_GADGET
          float m_volume;
          float m_amountNeeded;
          int m_position;
          std::string m_name;
          ReagentBottleType m_bottleType;
          Q_PROPERTY(float volume MEMBER m_volume)
          Q_PROPERTY(float amountNeeded MEMBER m_amountNeeded)
          Q_PROPERTY(int position MEMBER m_position)
          Q_PROPERTY(std::string name MEMBER m_name)
          Q_PROPERTY(ReagentBottleType bottleType MEMBER m_bottleType)
      };
      

      I define a BottleList in another class, but when I attempt to access properties (eg volume) from a method of that class, I get a "no member named 'volume'" error. Do I need to call a setContextProperty() for the BottleList object? That doesn't make sense to me.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mzimmers
        wrote on 3 Mar 2021, 22:03 last edited by mzimmers 3 Mar 2021, 22:07
        #3

        Still tinkering...

        struct BottleDataCC {
            Q_GADGET
            ...
        };
        Q_DECLARE_METATYPE(BottleDataCC)
        

        I was hoping that this would allow me to use the BottleDataCC type in my QML, but it's warning that it's an unknown type. Can someone show me what I'm forgetting here? (Hopefully not too many things)

        Thanks...

        EDIT: I guess it might help if I showed my QML as well:

          function getBottleData(index) {
              return changeConsumablesViewModel.getBottleData(index)
          }
        
        O 1 Reply Last reply 4 Mar 2021, 23:41
        0
        • M mzimmers
          3 Mar 2021, 22:03

          Still tinkering...

          struct BottleDataCC {
              Q_GADGET
              ...
          };
          Q_DECLARE_METATYPE(BottleDataCC)
          

          I was hoping that this would allow me to use the BottleDataCC type in my QML, but it's warning that it's an unknown type. Can someone show me what I'm forgetting here? (Hopefully not too many things)

          Thanks...

          EDIT: I guess it might help if I showed my QML as well:

            function getBottleData(index) {
                return changeConsumablesViewModel.getBottleData(index)
            }
          
          O Offline
          O Offline
          ODБOï
          wrote on 4 Mar 2021, 23:41 last edited by ODБOï 3 May 2021, 17:42
          #4

          @mzimmers hi

          // bottle struct with Q_GADGET macro
          struct Bottle {
              Q_GADGET
              Q_PROPERTY(int volume MEMBER volume)
            public:
              Bottle(){volume=55;}
              int volume;
          };
          
          // a class that will manage a list of Bottles. Expose an object from this class to you qml 
          class User : public QObject { 
              Q_OBJECT
          public:
              Q_INVOKABLE QVariant getBottleData (int ind){
                  return QVariant::fromValue(bottleList[ind]);
              }
              User (){
                  bottleList <<  QVariant::fromValue(Bottle()) << QVariant::fromValue(Bottle());
              }
              
            public slots:
              QVariantList getBottleList() {     
                  return bottleList;
              }
          private:
               QVariantList bottleList;
          };
          

          then in QML you can

                 var bottle  = user.getBottleData(0)
                 console.log(bottle.volume)
          
          M 1 Reply Last reply 5 Mar 2021, 17:25
          2
          • O ODБOï
            4 Mar 2021, 23:41

            @mzimmers hi

            // bottle struct with Q_GADGET macro
            struct Bottle {
                Q_GADGET
                Q_PROPERTY(int volume MEMBER volume)
              public:
                Bottle(){volume=55;}
                int volume;
            };
            
            // a class that will manage a list of Bottles. Expose an object from this class to you qml 
            class User : public QObject { 
                Q_OBJECT
            public:
                Q_INVOKABLE QVariant getBottleData (int ind){
                    return QVariant::fromValue(bottleList[ind]);
                }
                User (){
                    bottleList <<  QVariant::fromValue(Bottle()) << QVariant::fromValue(Bottle());
                }
                
              public slots:
                QVariantList getBottleList() {     
                    return bottleList;
                }
            private:
                 QVariantList bottleList;
            };
            

            then in QML you can

                   var bottle  = user.getBottleData(0)
                   console.log(bottle.volume)
            
            M Offline
            M Offline
            mzimmers
            wrote on 5 Mar 2021, 17:25 last edited by
            #5

            @LeLev thank you for the response; this is helpful. I do have a few follow-up questions:

            1. I'd like to make this class usable by other C++ classes. How do I return a BottleList from my QVariantList?
            2. your getBottleList() declares bottleList, which is also a member variable. Is this correct?
            3. I haven't gotten to this point yet, but I'm not clear on how the QML accesses the members of the BottleData object (for example, the volume). Do I use the property for this?

            Thanks again...

            O 1 Reply Last reply 5 Mar 2021, 17:41
            0
            • M mzimmers
              5 Mar 2021, 17:25

              @LeLev thank you for the response; this is helpful. I do have a few follow-up questions:

              1. I'd like to make this class usable by other C++ classes. How do I return a BottleList from my QVariantList?
              2. your getBottleList() declares bottleList, which is also a member variable. Is this correct?
              3. I haven't gotten to this point yet, but I'm not clear on how the QML accesses the members of the BottleData object (for example, the volume). Do I use the property for this?

              Thanks again...

              O Offline
              O Offline
              ODБOï
              wrote on 5 Mar 2021, 17:41 last edited by
              #6

              @mzimmers said in accessing aggregates (QVector of a struct):

              your getBottleList() declares bottleList, which is also a member variable. Is this correct?

              it's a mistake from me,obviously it should return the member variable QVariantList bottle List, and not declare anything . I will correct it

              @mzimmers said in accessing aggregates (QVector of a struct):

              I haven't gotten to this point yet, but I'm not clear on how the QML accesses the members of the BottleData object (for example, the volume). Do I use the property for this?

              please take time to read my answer, i did show an example of usage in qml

              @mzimmers said in accessing aggregates (QVector of a struct):

              I'd like to make this class usable by other C++ classes. How do I return a BottleList from my QVariantList?

              i don't know what do you mean here sorry, what class are you talking about ?

              M 1 Reply Last reply 5 Mar 2021, 18:45
              1
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on 5 Mar 2021, 18:04 last edited by
                #7

                Do your views need to react to changes in the data?
                The list might be appropriate as a property.

                Is the data updated all at once?
                Yes, then you can return the QVariantList as a property.
                No, then the list might be more appropriate as a model. This will allows updates to rows to be independent of each other.

                You can return a model as a qvariant this way: QVariant::fromValue(customModel) or as a QAbstractItemModel*. The latter is in the meta object system that qml can recognize.

                The reason I show the QVariant::fromValue is because I needed to return a model from a model in the data() call in my code. Something I just figured out.

                Also, this page might be helpful to know what is by default accessible to QML from C++.

                C++ is a perfectly valid school of magic.

                1 Reply Last reply
                1
                • O ODБOï
                  5 Mar 2021, 17:41

                  @mzimmers said in accessing aggregates (QVector of a struct):

                  your getBottleList() declares bottleList, which is also a member variable. Is this correct?

                  it's a mistake from me,obviously it should return the member variable QVariantList bottle List, and not declare anything . I will correct it

                  @mzimmers said in accessing aggregates (QVector of a struct):

                  I haven't gotten to this point yet, but I'm not clear on how the QML accesses the members of the BottleData object (for example, the volume). Do I use the property for this?

                  please take time to read my answer, i did show an example of usage in qml

                  @mzimmers said in accessing aggregates (QVector of a struct):

                  I'd like to make this class usable by other C++ classes. How do I return a BottleList from my QVariantList?

                  i don't know what do you mean here sorry, what class are you talking about ?

                  M Offline
                  M Offline
                  mzimmers
                  wrote on 5 Mar 2021, 18:45 last edited by
                  #8

                  Let me back up a bit: for this overall effort, there are three distinct (though overlapping) efforts:

                  1. to collect the (current) information about the fill levels in 16 bottles in a rack. This is purely a C++ effort, and I've got it working.
                  2. to put the information into a form that is available to QML.
                  3. to render the information on a QML screen.

                  To answer fcarney's question, let's assume that the view should indeed be dynamic. I can update all the information on demand (from C++, which is adequate).

                  In my C++, I'd like to maintain a BottleList (as opposed to a QVariantList) for debugging purposes only. (Maybe there's a way to meaningfully examine the contents of a QVariantList in gdb, but I don't know of it.) I'm assuming that the QML needs a QVariant, right? I think it would be easier to implement a function that casts the list to a QVariantList for the QML, but I'm interested in others' opinions on this.

                  Thanks...

                  1 Reply Last reply
                  0
                  • fcarneyF Offline
                    fcarneyF Offline
                    fcarney
                    wrote on 5 Mar 2021, 18:51 last edited by
                    #9

                    The most basic would be a QVariantList that is a property. It would have a signal so that when the list is changed then the C++ can notify view. This will require a QVariantList to be built every time anything changes. For 16 items this is probably not a big deal. Keep your BottelList as is. The function that returns the values for the property can convert the entire list. The code that makes changes to the BottleList would need to fire the signal on changes.

                    C++ is a perfectly valid school of magic.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mzimmers
                      wrote on 5 Mar 2021, 21:42 last edited by
                      #10

                      Thanks for the information, guys. I'm making progress, but still can't quite connect all the dots. I've created a BottleList class, with a method:

                      QVariantList BottleList::getBottleListQv() {
                          QVariantList qvl;
                          BottleData bd;
                          for (int i = 0; i < NBR_BOTTLES; ++i) {
                              bd = getBottleData(i);
                              qvl.append(QVariant::fromValue(bd));
                          }
                          return qvl;
                      }
                      

                      Another class ChangeConsumables creates an instance of BottleList.

                      from my QML file:

                              function getRackData() {
                                  var bottleRack = changeConsumablesViewModel.getBottleListQv()
                                  return bottleRack
                              }
                              Bottle {
                                  id: bottle1
                                  cellText: "W7"
                                  cellColor: "red"
                              }
                      

                      I have 16 entries similar to bottle1.

                      So, what I'm missing is...how to replace the hard-coded "W7" with the name field from the BottleData struct in my BottleList class?

                      Thanks.

                      kshegunovK 1 Reply Last reply 5 Mar 2021, 22:00
                      0
                      • M mzimmers
                        5 Mar 2021, 21:42

                        Thanks for the information, guys. I'm making progress, but still can't quite connect all the dots. I've created a BottleList class, with a method:

                        QVariantList BottleList::getBottleListQv() {
                            QVariantList qvl;
                            BottleData bd;
                            for (int i = 0; i < NBR_BOTTLES; ++i) {
                                bd = getBottleData(i);
                                qvl.append(QVariant::fromValue(bd));
                            }
                            return qvl;
                        }
                        

                        Another class ChangeConsumables creates an instance of BottleList.

                        from my QML file:

                                function getRackData() {
                                    var bottleRack = changeConsumablesViewModel.getBottleListQv()
                                    return bottleRack
                                }
                                Bottle {
                                    id: bottle1
                                    cellText: "W7"
                                    cellColor: "red"
                                }
                        

                        I have 16 entries similar to bottle1.

                        So, what I'm missing is...how to replace the hard-coded "W7" with the name field from the BottleData struct in my BottleList class?

                        Thanks.

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on 5 Mar 2021, 22:00 last edited by
                        #11

                        You can refer to the object by id. Like this:

                        function loadRackDataFirst() {
                            bottle1.cellText = changeConsumablesViewModel.getBottleListQv()[0].name
                        }
                        

                        However you should convert to QString.

                        Read and abide by the Qt Code of Conduct

                        M 1 Reply Last reply 5 Mar 2021, 22:29
                        0
                        • fcarneyF Offline
                          fcarneyF Offline
                          fcarney
                          wrote on 5 Mar 2021, 22:21 last edited by fcarney 3 May 2021, 22:23
                          #12
                          Repeater {
                            model: changeConsumablesViewModel.getBottleListQv() // or use property, a property will have a signal to update if the list changes
                            Bottle {
                              cellText: modelData.name
                            }
                          }
                          

                          If you want more interaction then a model might be more appropriate.

                          modelData Search for modelData on that page to understand where it comes from.

                          C++ is a perfectly valid school of magic.

                          M 1 Reply Last reply 5 Mar 2021, 22:33
                          0
                          • kshegunovK kshegunov
                            5 Mar 2021, 22:00

                            You can refer to the object by id. Like this:

                            function loadRackDataFirst() {
                                bottle1.cellText = changeConsumablesViewModel.getBottleListQv()[0].name
                            }
                            

                            However you should convert to QString.

                            M Offline
                            M Offline
                            mzimmers
                            wrote on 5 Mar 2021, 22:29 last edited by
                            #13

                            @kshegunov the "name" field isn't accessible as I've currently implemented it. I think I may have over-designed this. I've made several changes since my earlier posts, so let me recap my code:

                            The struct:

                            struct BottleData {
                              Q_GADGET
                            public:
                              uint32_t m_volume;               // amount in bottle (in uL)
                              uint32_t m_amountNeeded;         // amount needed for synth (in uL)
                              int m_position;                  // still figuring this one out
                              std::string m_name;              // name of the reagent
                              ReagentBottleType m_bottleType;  // bottle type.
                              Q_PROPERTY(uint32_t volume MEMBER m_volume)
                              Q_PROPERTY(uint32_t amountNeeded MEMBER m_amountNeeded)
                              Q_PROPERTY(int position MEMBER m_position)
                              Q_PROPERTY(std::string name MEMBER m_name)
                              Q_PROPERTY(ReagentBottleType bottleType MEMBER m_bottleType)
                            };
                            Q_DECLARE_METATYPE(BottleData)
                            

                            The class:

                            typedef QVector<BottleData> BottleDataList;
                            
                            class BottleList : public QObject
                            {
                                Q_OBJECT
                            private:
                                BottleDataList m_bottleList;
                            public:
                                explicit BottleList(QObject *parent = nullptr);
                                Q_PROPERTY(QVariantList qvl READ getBottleListQv)
                                QVariantList getBottleListQv();
                                ...
                            

                            From reading the docs, I was under the impression that I wouldn't need a getter for the fields in the struct, because I used the MEMBER macro. Did I misinterpret this?

                            fcarneyF kshegunovK 2 Replies Last reply 5 Mar 2021, 22:38
                            0
                            • fcarneyF fcarney
                              5 Mar 2021, 22:21
                              Repeater {
                                model: changeConsumablesViewModel.getBottleListQv() // or use property, a property will have a signal to update if the list changes
                                Bottle {
                                  cellText: modelData.name
                                }
                              }
                              

                              If you want more interaction then a model might be more appropriate.

                              modelData Search for modelData on that page to understand where it comes from.

                              M Offline
                              M Offline
                              mzimmers
                              wrote on 5 Mar 2021, 22:33 last edited by mzimmers 3 May 2021, 22:34
                              #14

                              @fcarney that looks really powerful. The complete definition of each model is like this:

                                      Bottle {
                                          id: bottle1
                                          cellX: 25
                                          cellY: 105
                                          cellHeight: 75
                                          cellWidth: 75
                                          bottleScaleFactor: scaleFactor
                                          cellText: "W7"
                                          cellColor: "red"
                                      }
                              

                              If I use the repeater to load the names, can I alter the individual bottles afterwards?

                              Thanks...

                              PS: I'm aware that there's a lot of ugly hard-coding in here; I was going to address that after I got the connections working.

                              1 Reply Last reply
                              0
                              • fcarneyF Offline
                                fcarneyF Offline
                                fcarney
                                wrote on 5 Mar 2021, 22:36 last edited by fcarney 3 May 2021, 22:38
                                #15

                                If I use the repeater to load the names, can I alter the individual bottles afterwards?

                                It only alters the copy given to the Repeater. It has no way to get that data back.

                                I have not used Q_GADGETs before. What does it print out when you console.log(modelData)? Curious as what QML thinks that objects is.

                                C++ is a perfectly valid school of magic.

                                M 1 Reply Last reply 5 Mar 2021, 22:38
                                0
                                • M mzimmers
                                  5 Mar 2021, 22:29

                                  @kshegunov the "name" field isn't accessible as I've currently implemented it. I think I may have over-designed this. I've made several changes since my earlier posts, so let me recap my code:

                                  The struct:

                                  struct BottleData {
                                    Q_GADGET
                                  public:
                                    uint32_t m_volume;               // amount in bottle (in uL)
                                    uint32_t m_amountNeeded;         // amount needed for synth (in uL)
                                    int m_position;                  // still figuring this one out
                                    std::string m_name;              // name of the reagent
                                    ReagentBottleType m_bottleType;  // bottle type.
                                    Q_PROPERTY(uint32_t volume MEMBER m_volume)
                                    Q_PROPERTY(uint32_t amountNeeded MEMBER m_amountNeeded)
                                    Q_PROPERTY(int position MEMBER m_position)
                                    Q_PROPERTY(std::string name MEMBER m_name)
                                    Q_PROPERTY(ReagentBottleType bottleType MEMBER m_bottleType)
                                  };
                                  Q_DECLARE_METATYPE(BottleData)
                                  

                                  The class:

                                  typedef QVector<BottleData> BottleDataList;
                                  
                                  class BottleList : public QObject
                                  {
                                      Q_OBJECT
                                  private:
                                      BottleDataList m_bottleList;
                                  public:
                                      explicit BottleList(QObject *parent = nullptr);
                                      Q_PROPERTY(QVariantList qvl READ getBottleListQv)
                                      QVariantList getBottleListQv();
                                      ...
                                  

                                  From reading the docs, I was under the impression that I wouldn't need a getter for the fields in the struct, because I used the MEMBER macro. Did I misinterpret this?

                                  fcarneyF Offline
                                  fcarneyF Offline
                                  fcarney
                                  wrote on 5 Mar 2021, 22:38 last edited by fcarney 3 May 2021, 22:44
                                  #16

                                  @mzimmers said in accessing aggregates (QVector of a struct):

                                  From reading the docs, I was under the impression that I wouldn't need a getter for the fields in the struct, because I used the MEMBER macro. Did I misinterpret this?

                                  I "think" so. DOH! I meant to agree to the MEMBER macro doing that, not you misinterpreting this.

                                  C++ is a perfectly valid school of magic.

                                  1 Reply Last reply
                                  0
                                  • fcarneyF fcarney
                                    5 Mar 2021, 22:36

                                    If I use the repeater to load the names, can I alter the individual bottles afterwards?

                                    It only alters the copy given to the Repeater. It has no way to get that data back.

                                    I have not used Q_GADGETs before. What does it print out when you console.log(modelData)? Curious as what QML thinks that objects is.

                                    M Offline
                                    M Offline
                                    mzimmers
                                    wrote on 5 Mar 2021, 22:38 last edited by
                                    #17

                                    @fcarney my console.log isn't working for this app, so I can't tell you. I discovered Q_GADGET from some online searching; in simplest terms, it's a lightweight version of Q_OBJECT (no signals/slots).

                                    I'm not at all concerned with updating anything other than my display. But now you have me wondering where I should really define all those values. (I would rather not use JSON, but that's probably the right way to do this.)

                                    fcarneyF 1 Reply Last reply 5 Mar 2021, 22:41
                                    0
                                    • M mzimmers
                                      5 Mar 2021, 22:38

                                      @fcarney my console.log isn't working for this app, so I can't tell you. I discovered Q_GADGET from some online searching; in simplest terms, it's a lightweight version of Q_OBJECT (no signals/slots).

                                      I'm not at all concerned with updating anything other than my display. But now you have me wondering where I should really define all those values. (I would rather not use JSON, but that's probably the right way to do this.)

                                      fcarneyF Offline
                                      fcarneyF Offline
                                      fcarney
                                      wrote on 5 Mar 2021, 22:41 last edited by fcarney 3 May 2021, 22:48
                                      #18

                                      @mzimmers If you want your display to interact with the data then a full blown QAbstractListModel would be a better fit. Then each piece of the BottleData object could be its own role. With a setData routine you can edit that model.

                                      C++ is a perfectly valid school of magic.

                                      1 Reply Last reply
                                      0
                                      • M mzimmers
                                        5 Mar 2021, 22:29

                                        @kshegunov the "name" field isn't accessible as I've currently implemented it. I think I may have over-designed this. I've made several changes since my earlier posts, so let me recap my code:

                                        The struct:

                                        struct BottleData {
                                          Q_GADGET
                                        public:
                                          uint32_t m_volume;               // amount in bottle (in uL)
                                          uint32_t m_amountNeeded;         // amount needed for synth (in uL)
                                          int m_position;                  // still figuring this one out
                                          std::string m_name;              // name of the reagent
                                          ReagentBottleType m_bottleType;  // bottle type.
                                          Q_PROPERTY(uint32_t volume MEMBER m_volume)
                                          Q_PROPERTY(uint32_t amountNeeded MEMBER m_amountNeeded)
                                          Q_PROPERTY(int position MEMBER m_position)
                                          Q_PROPERTY(std::string name MEMBER m_name)
                                          Q_PROPERTY(ReagentBottleType bottleType MEMBER m_bottleType)
                                        };
                                        Q_DECLARE_METATYPE(BottleData)
                                        

                                        The class:

                                        typedef QVector<BottleData> BottleDataList;
                                        
                                        class BottleList : public QObject
                                        {
                                            Q_OBJECT
                                        private:
                                            BottleDataList m_bottleList;
                                        public:
                                            explicit BottleList(QObject *parent = nullptr);
                                            Q_PROPERTY(QVariantList qvl READ getBottleListQv)
                                            QVariantList getBottleListQv();
                                            ...
                                        

                                        From reading the docs, I was under the impression that I wouldn't need a getter for the fields in the struct, because I used the MEMBER macro. Did I misinterpret this?

                                        kshegunovK Offline
                                        kshegunovK Offline
                                        kshegunov
                                        Moderators
                                        wrote on 5 Mar 2021, 22:43 last edited by kshegunov 3 May 2021, 22:51
                                        #19

                                        @mzimmers said in accessing aggregates (QVector of a struct):

                                        Q_DECLARE_METATYPE(BottleData)
                                        

                                        is already done by the Q_GADGET so it's superfluous.

                                        Switch

                                        std::string m_name;
                                        

                                        to QString.

                                        Register the type with QML (qmlRegisterType) if you intend to create instances of it from there.

                                        From reading the docs, I was under the impression that I wouldn't need a getter for the fields in the struct, because I used the MEMBER macro. Did I misinterpret this?

                                        Nope, this is correct as far as I recall.

                                        If I use the repeater to load the names, can I alter the individual bottles afterwards?

                                        I don't think so, but I'm a noobster with QML. I believe you can imperatively create the items like this (untested):

                                        Component {
                                                id: component
                                                Bottle { cellText: "default text" }
                                                onCompleted: changeConsumablesViewModel.getBottleListQv().forEach(element => function(element)  {
                                                   createObject(parentItemId, { cellText: element.name });
                                                }, this);
                                        }
                                        

                                        or something akin.

                                        Read and abide by the Qt Code of Conduct

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          mzimmers
                                          wrote on 5 Mar 2021, 23:05 last edited by
                                          #20

                                          OK, so why doesn't this work?

                                              Rectangle {
                                                  id: rack
                                                  function getBottleName(i) {
                                                      return changeConsumablesViewModel.getBottleListQv()[i].m_name
                                                  }
                                                  Bottle {
                                                      cellText: rack.getBottleName(0)// "W7"
                                                  }
                                          

                                          I get this error on the line with the "return" statement:

                                          TypeError: Cannot read property 'm_name' of undefined

                                          kshegunovK 1 Reply Last reply 5 Mar 2021, 23:08
                                          0

                                          1/52

                                          2 Mar 2021, 23:03

                                          • Login

                                          • Login or register to search.
                                          1 out of 52
                                          • First post
                                            1/52
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved