you must use have (or find) some way to find out where the binary part starts.
You can read that with QDataStream (if it was written by it).
// untested and uncompiled
{
do {
QString line
= textinput.
readLine();
if (line.isNull() && textinput.atEnd()) { cerr << "done\n"; break; }
cerr << "read: " << qPrintable(line) << std::endl;
if (line == "BINARY_FROM_NOW_ON") break; // this is assuming you have a line containing this text to mark the start of the binary part of your file
}
QDataSteam in(&file);
// read binary stuff here
}
// untested and uncompiled
if (file.open(QIODevice::Readonly))
{
QTextStream textinput(&file);
do {
QString line = textinput.readLine();
if (line.isNull() && textinput.atEnd()) { cerr << "done\n"; break; }
cerr << "read: " << qPrintable(line) << std::endl;
if (line == "BINARY_FROM_NOW_ON") break; // this is assuming you have a line containing this text to mark the start of the binary part of your file
}
QDataSteam in(&file);
// read binary stuff here
}
To copy to clipboard, switch view to plain text mode
Also, note that your code is buggy:
you alloce a single byte (in; data = new char and then tell Qt to read a 1000 bytes into that "buffer".
Apart from the fact that dynamic memory allocation is not needed here.
try
char buffer[1000];
in.readRawData(buffer, 1000);
char buffer[1000];
in.readRawData(buffer, 1000);
To copy to clipboard, switch view to plain text mode
Bookmarks