can`t read a binary data!
the binary file is generated from another software,
it includes text and data, a mixed binary file,
and i want use
file.open(QIODevice::Readonly)
to read it, but unsuccessfully,
can QFile only read the binary file which generated from QFile?:confused:
thanks for your HELP!
Re: can`t read a binary data!
What error cause does QFile::errorString() give?
(On linux: make sure you have read permissions and, of course, that the path to the file is correct.)
Re: can`t read a binary data!
Quote:
Originally Posted by
caduel
What error cause does
QFile::errorString() give?
(On linux: make sure you have read permissions and, of course, that the path to the file is correct.)
i have tested,
Code:
{
QDataSteam in(&file);
in >> inin;
textEdit->setPlainText(inin);
}
else
cerr<<file.error();
the feedback is 5, that means The file could not be opened.
but actually i can open it use Textpad:(
Re: can`t read a binary data!
print errorString() as well
Re: can`t read a binary data!
where can i use the errorstring()? haven`t found,
now i can read the File successfully, but not output
the File is consist of a section text date and then a section binary data,
i don`t know how i can do it !:(
Re: can`t read a binary data!
errorString() is a method of QFile's base class QIOStream.
What do you mean a section of text and binary?
Using QDataStream you will read binary data.
Your code
Code:
QDataSteam in(&file);
in >> inin;
will not read some ascii from a (text) file, but rather the serialized binary representation of a QString which is something entirely different.
If you read ascii text with that code, interesting but unintended things will happen.
Re: can`t read a binary data!
thanks,
I means that this File is consist of a section of Text and then a section of binay raw date.
i can open this file with TextPad, but i can just only discern the head section (Text data), the latter is the binay raw data and i can`t discern them
.
I rewrite my code,
Code:
{
cerr<<file.error();
QDataSteam in(&file);
data = new char;
k = 1000;
in.readRawData(data, k);
cerr<<data;
textEdit->setPlainText(inin);
delete data;
}
i can see the feedback 0, then no more output:confused:
Re: can`t read a binary data!
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).
Code:
// 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
}
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
Code:
char buffer[1000];
in.readRawData(buffer, 1000);
Re: can`t read a binary data!
thank u very much, caduel!
where the binary part starts is difficult to find,
because the text part is a variable long text (a section of commentary),
then is die binary part,
no Mark!
I will try to find a good way to distinguish..
thanks again!:o