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. Append struct into nested QList don't work [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Append struct into nested QList don't work [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.9k 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.
  • C Offline
    C Offline
    ChanchoCiego
    wrote on last edited by
    #1

    Hello,

    This does not work, what am I doing wrong?

    I appreciate the help,

    regards,

    @
    struct StructA
    {
    QString strStrA;
    unsigned int uintStrA;
    qreal qrlStrA;

    StructA(void)
    {
        uintStrA = 0;
        qrlStrA  = 0;
    }
    

    }

    struct StructB
    {
    QString strStrB;
    unsigned int uintStrB;
    qreal qrlStrB;

    QList<StructA> lstStructA;
    
    StructB(void)
    {
        uintStrB = 0;
        qrlStrB  = 0;
    }
    

    }

    void procedure(void)
    {
    QList<StructB> lstStructB;

    StructB strb;
    StructA stra;
    
    strb.strStrB  = "abc";
    strb.uintStrB = 1;
    strb.qrlStrB  = 2;
    
    stra.strStrA  = "def";
    stra.uintStrA = 3;
    stra.qrlStrA  = 4;
    
    strb.lstStructA.append( stra ); // this works
    lstStructB.append( strb );
    
    StructA structa;
    
    structa.strStrA  = "ghi";
    structa.uintStrA = 5;
    structa.qrlStrA  = 6;
    
    // this does not work, compiling reports
    // "error: C2663: 'QList <T> :: append': 2 overloads have no meaningful
    // conversion to pointer 'this' with [T = StructA]"
    lstStructB.at( lstStructB.size()-1 ).lstStructA.append( structa );
    

    }
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      QList returns const objects. You can't modiy the objects by calling "append" on them. Consider using takeAt() method instead.

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChanchoCiego
        wrote on last edited by
        #3

        Hello sierdzio, thanks for reply,

        I apologize, the QList man says:

        bq. QList uses 0-based indexes, just like C++ arrays. To access the item at a particular index position, you can use operator [] (). On non-const lists, operator [] () returns a reference to the item and can be used on the left side of an assignment:

        in the following line:

        bq. Because QList is implemented as an array of pointers, this operation is very fast (constant time). For read-only access, an alternative syntax is to use at()

        a mistake of mine,

        I ask apologies and thank you for the reply,

        Best regards

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Hey, no problem. That is one of the reasons this forum exists: to solve issues like this one :)

          (Z(:^

          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