i need the checksum of a file and found this, which works perfectly fine. Now i want to change this function to take a pointer to a QIODevice
that has been opened before with the following lines:
if (!file.open(QFile::ReadOnly | QFile::Text))
{
...
}
This is passed to read (reader.read(&file);
) as device:
bool XmlReader::read(QIODevice* device)
{
QByteArray b = fileChecksum(device);
...
}
This is my implementation of fileChecksum. It returns a checksum, but i am caught in a loop forever and i am getting an xml parse error. What am i doing wrong here?
QByteArray XmlReader::fileChecksum(QIODevice* device)
{
if (device->isOpen())
{
QCryptographicHash hash(QCryptographicHash::Sha256);
if (hash.addData(device)) {
return hash.result();
}
}
return QByteArray();
}
EDIT
right after QByteArray b = fileChecksum(device);
i do:
qDebug() << "Checksum: " << b.toHex();
whick keeps printing and printing and printing...
The parse error is: premature end of document
which is rubbish.
Hope this helps.