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(); } 
  1. how connect file name , contents of 1 variable of type qbytearray?
  2. 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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -