[Interest] Binary file embedded in Resources to std::istream
Karl Ruetz
karl.ruetz at ruetzdogz.com
Fri Aug 2 22:05:55 CEST 2013
I'd try QDataStream.
For input:
QFile
file("file.xxx");
file.open(QIODevice::ReadOnly);
QDataStream in(&file);
use >> operator or readBytes method to read
for output:
QFile
file("file.xxx");
file.open(QIODevice::WriteOnly);
QDataStream
out(&file);
use << operator or writeBytes() method to write.
Karl
On 2013-08-02 13:18, Rollastre Prostrit wrote:
> Hi Qters:
>
> Due
to vicissitudes of a third party library I'm using I have to read
> the
bytes of png files (binary files) embedded in the resources via
> using
a std::istream. I have been struggling quite a bit with this and
>
googling a lot without success. Maybe this is something that it is easy
> to solve but I haven't succeeded with it yet.
>
> I use this
snippet
>
> QFile f(":/images/file.png");
>
> if (!f.exist())
>
return;
>
> if (f.size()<=0)
> return;
>
> if
(!f.open(QIODevice::ReadOnly))
> return;
>
> if (!f.isReadable())
>
return;
>
> QByteArray bytes = f.readAll();
>
> char* bb =
bytes.data();
> std::string str;
> for (int i=0; i<s; ++i)
> {
> str +=
bb[i];
> }
>
> stringstream stream;
> stream << str;
>
> I use strings
here because some of the tens of articles I've read
> suggested it. It
doesn't seem to work, though. If I dump the bytes to a
> temp file, I
see the file becomes corrupted. There is an extra empty
> byte right
after the PNG header. My guess is that the zero-end byte is
> messing
everything up. But I admit that I don't find any solution for this.
>
>
Has somebody faced this problem and/or can see what/how is the
solution?
> Thanks in advance!
>
_______________________________________________
> Interest mailing
list
> Interest at qt-project.org
>
http://lists.qt-project.org/mailman/listinfo/interest [1]
Links:
------
[1]
http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130802/a40c7165/attachment.html>
More information about the Interest
mailing list