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. QByteArray resize/sizeof problem.
Forum Updated to NodeBB v4.3 + New Features

QByteArray resize/sizeof problem.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k 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.
  • S Offline
    S Offline
    Stasi4ek
    wrote on last edited by
    #1

    Good Day!
    I have a problem.
    @
    QByteArray arr;
    QTextStream out(&file);
    arr.resize(5);
    out << sizeof(arr);
    I receive 4. why?
    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Stasi4ek
      wrote on last edited by
      #2

      not solved

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

        QByteArray adds \0 to your data. Sizeof might miss that. Or it reports something completely different. Use QByteArray::size() instead.

        (Z(:^

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          The sizeof() a QByteArray object has nothing to do with the amount of data the object manages. It is the size of the object member variables used to track the array content. QByteArray operates a private implementation object and likely only contains a 4 byte pointer to that private object; hence the reported size.

          sierdzio has the function that reports the amount of data in the QByteArray.

          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