QFile file( fileName );QString sumMD5;sumMD5.clear();if ( file.open( QIODevice::ReadOnly ) ) { MD5 hash; QString line; QDataStream in( &file ); while (!in.atEnd()) { line.clear(); in >> line; hash.update(line); } sumMD5 = hash.final(); file.close(); }
.... QTextStream in(&file); while (!in.atEnd()) { line.clear(); line = in.readLine(); hash.update(line); } ....
QString sumMD5; sumMD5.clear(); MD5 hash; QFile *filech = new QFile( fileName ); if (filech->open(QIODevice::ReadOnly | QIODevice::Text)) { while (!filech->atEnd()) { QByteArray line = filech->readLine(); hash.update(line); } sumMD5 = hash.final(); } filech->close();
int main(int argc, char *argv[]){ QCoreApplication app(argc, argv); QCryptographicHash hash(QCryptographicHash::Md5); QFile file("md5.cpp"); if (!file.open(QIODevice::ReadOnly) ) return -1; QByteArray all; while (!file.atEnd()) { QByteArray line = file.read(1024); hash.addData(line); all+=line; } fprintf(stderr, "%s\r\n",hash.result().toHex().data() ); fprintf(stderr, "%s\r\n",QCryptographicHash::hash(all,QCryptographicHash::Md5).toHex().data() ); return 0;}