[Qt-interest] Writing QIODevice's data to a QByteArray

Sean Harmer sean.harmer at maps-technology.com
Thu Dec 10 20:41:23 CET 2009


Hi,

Rohan Prabhu wrote:
> Let's say I have this QIODevice:
> 
> QIODevice* myDevice = getIODevice(); //just some function with which I 
> get an IODevice pointer
> 
> and in some function [slot]:
> void onDeviceRead() {
>     QByteArray* ba = getByteArray(); //some other function. NOTE: This 
> QByteArray may not neccessarily be empty
>     //....
> }
> 
> and:
> 
> QObject::connect(myDevice, SIGNAL(readyRead()), this, SLOT(onDeviceRead()));
> 
> Now, I want to append whatever data is there in the QIODevice [the size 
> given by: getIODevice->bytesAvailable()] to the byteArray. I just need 
> to know the methods to do it. I mean, the function onDeviceRead() has 
> access to the myDevice QIODevice object...

Something like this should do...


void onDeviceRead()
{
     QByteArray* ba = getByteArray();
     if ( myDevice->bytesAvailable() > 0 )
         ba += myDevice->readAll();
}

Sean



More information about the Qt-interest-old mailing list