利用QDataStream将大文件转化成二进制文件QBatyArray

用QDataStream的readRawData()函数读取二进制的文件,文件过大时会造成程序崩溃,我们可以多次读取文件,然后将数据块组合成整体的QByteArray

  QByteArray total_file;
  QFile file("D:/jpeg.jpg");
  int flag=file.open(QIODevice::ReadOnly);
  QDataStream in(&file);
  QFileInfo fileInfo("D:/jpeg.jpg");
  int buffer_size=65535;
  char datRawArray[buffer_size];
  qDebug()<<"nomal"<<fileInfo.size()<<endl;
  int total_size=0;
  while(!in.atEnd()){
      in.readRawData(datRawArray, buffer_size);
      QByteArray block(datRawArray,buffer_size);
      total_file=total_file+block;
  }
qDebug()<<"read file finished,yotal size:"<<total_file.size()<<endl;
展开阅读全文

没有更多推荐了,返回首页