Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

QT, Copy data from QDataStream to QByteArray

Posted on 2011-03-11
2
Medium Priority
?
2,224 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

650 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