c++ - Parsing QByteArray -
i have file name qbytearray
qstring file_name = "icon.jpg"; qbytearray qba1; qba+=file_name;
i have contents of file qbytearray
qfile file("c:\\devel\\icon.jpg"); if (file.open(qiodevice::readonly)){ qbytearray content = file.readall(); }
- how connect file name , contents of 1 variable of type qbytearray?
- how parse variable qbytearray file name , content?
simplest way start length of filename, filename itself, followed data. parsing data simple reading filename-length first, read filename, data.
qbytearray qbafilename((const char*)(file_name.utf16()), file_name.size() * 2); qbytearray bytearray; qdatastream stream(&bytearray, qiodevice::writeonly); stream << (int)qbafilename.size(); // put length of filename on stream stream << qbafilename; // put filename on stream stream << file.readall(); // put binary data on stream
Comments
Post a Comment