?
Solved

QT, Copy data from QDataStream to QByteArray

Posted on 2011-03-11
2
Medium Priority
?
2,115 Views
Last Modified: 2012-05-11
Hi experts,

I have a QDataStream with data read from a file. Every 2 bytes in this file are a signed integer value.

How do I copy the data in the data stream to a QByteArray ?

For example:

QByteArray inputf1;
QDataStream in1(&filein1);

I need to copy the data from input in1 to inputf1.

Thanks,
Peter
0
Comment
Question by:PeterVarain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
sarabande earned 2000 total points
ID: 35107272
you could use resize function of QByteArray to get proper size and then cast off constness off from constData function to get a writeable char buffer.

  QByteArray inputf1;
  QDataStream in1(&filein1);
   inputf1.resize(4096);
   in1.readRawData(const_cast<char*)(inputf1.constData()), 4096);

but that is a bit unsafe because of the cast.

if memory isn't an issue i would use a temporary char buffer for read and move it to QByteArray using the insert function after read.

Sara



0
 

Author Closing Comment

by:PeterVarain
ID: 35114839
Thanks!
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question