Solved

QT, Copy data from QDataStream to QByteArray

Posted on 2011-03-11
2
1,949 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 34

Accepted Solution

by:
sarabande earned 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

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…
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é.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses

738 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