[KDE-India] Reading Binary file
Till Adam
adam at kde.org
Mon Jan 9 22:40:41 CET 2006
On Monday 09 January 2006 07:10, Aditya Mooley wrote:
> On 1/7/06, Till Adam <adam at kde.org> wrote:
> > On Saturday 07 January 2006 13:43, you wrote:
> > > On 1/7/06, Till Adam <adam at kde.org> wrote:
> > > > On Saturday 07 January 2006 12:57, Aditya Mooley wrote:
> > > > > QFile userfile(fileName);
> > > > > if ( !userfile.open(IO_ReadOnly) ) {
> > > > > QMessageBox::information(this, tr("HTTP"),
> > > > > tr("Unable to open the file %1: %2.")
> > > > > .arg(openFilesPath).arg(userfile.errorString()));
> > > > > }
> > > > > fileSize = userfile.size();
> > > > > userfile.readAll();
> > > >
> > > > Hm, you're not doing anything with teh read data here, so I can't
> >
> > really
> >
> > > > tell
> > > > what the problem could be. Can you post the full source, maybe, or
> >
> > send
> >
> > > > it to
> > > > me in private mail?
> > >
> > > Thanks for your prompt response. It's encouraging :)
> > > I am attaching the source code for you to see.
> >
> > Hm, the file reading code looks correct. Does the right data get added to
> > teh
> > ByteArray? If you print out the bytearray, after the readAll, for
> > example, does it have the stuff in there?
> Please let me what's wrong in the code or am I missing something?
Ah, I see now. The problem is that you are using QCString::append() to add the
file to the ByteArray. That will look for a terminating \0 in the string and
use the data only until that byte. Which in the case of PNG is the 6th byte
or so, due to the png header. You'll have to memcopy the data into the target
bytearray, treating it as a QCString won't work.
Till
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-india/attachments/20060109/b9f0b4b6/attachment.pgp
More information about the KDE-india
mailing list