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. Problems Accesing a List of QByteArray
Forum Update on Monday, May 27th 2025

Problems Accesing a List of QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 479 Views
  • 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.
  • NicolasKsiN Offline
    NicolasKsiN Offline
    NicolasKsi
    wrote on last edited by
    #1

    Hi everyone! Im having kind of a basic problem.
    I have a list of QByteArray. I want to populate this list, byte by byte.

    This is an example of how I create my list

    QList<QByteArray> List;
    QByteArray Array1,Array2,Array3;
    List.append(Array1);
    List.append(Array2);
    List.append(Array3);
    

    How i Usually populate a single QByteArray

    QByteArray Test;
    unsigned char a=0x55;
    Test.append(a);
    

    So far so good. Now i want to append a byte to a QByteArray thats contained in my list.

    QList<QByteArray> List;
    QByteArray Array1,Array2,Array3;
    List.append(Array1);
    List.append(Array2);
    List.append(Array3);
    
    unsigned char a=0x55;
    List.at(1).append(a);
    

    What im trying to do, is to my Array2 (The one that is placed on position 1 of List) append the byte a (that contains 0x55)

    The following error code appears:

    passing 'const QByteArray'as 'this' argument of 'QByteArray& QByteArray::append(char)' discards qualifiers [-fpermissive]

    If i change it to this (which i consider kind of the same)

    ((QByteArray)List.at(1)).append(a);
    

    The program compiles, but it doesnt work, no result after that line.

    If i place the mouse over the List.at(1) part, the sign QByteArray Appears. so calling List.at(1) returns a QByteArray..., Then why cant i append a byte to that QByteArray?
    Thanks in advance!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on last edited by luca
      #2

      QList::at() returns a const reference so you can't modify it.

      You should use:

      List[1].append(...) ;
      
      1 Reply Last reply
      2

      • Login

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