Chinaunix首页 | 论坛 | 博客
  • 博客访问: 35209
  • 博文数量: 6
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 33
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-05 10:14
文章分类

全部博文(6)

文章存档

2015年(6)

我的朋友

分类: 其他平台

2015-12-17 14:45:03


点击(此处)折叠或打开

  1. /**
  2.  * @brief FuncModuleWin::copyFile 
  3.  * @param fromFIleName 优盘里面的文件
  4.  * @param toFileName 拷贝到/bin里面的启动文件
  5.  * @return
  6.  */
  7. bool FuncModuleWin::copyFile(const QString &fromFIleName, const QString &toFileName)
  8. {
  9.     char* byteTemp = new char[4096];//字节数组
  10.     int fileSize = 0;
  11.     int totalCopySize = 0;
  12.     QFile tofile;
  13.     ui->progressBar_copy->setValue(0);
  14.     tofile.setFileName(toFileName);
  15.     QDataStream out(&tofile);
  16.     out.setVersion(QDataStream::Qt_4_8);

  17.     QFile fromfile;
  18.     fromfile.setFileName(fromFIleName);
  19.     if(!fromfile.open(QIODevice::ReadOnly)){
  20.         qDebug() << "open fromfile failed!!!";
  21.         return false;
  22.     }
  23.     fileSize = fromfile.size();
  24.     QDataStream in(&fromfile);

  25.     in.setVersion(QDataStream::Qt_4_8);
  26.     ui->progressBar_copy->setRange(0, fileSize);
  27.     while(!in.atEnd())
  28.     {
  29.         int readSize = 0;
  30.         //读入字节数组,返回读取的字节数量,如果小于4096,则到了文件尾
  31.         readSize = in.readRawData(byteTemp, 4096);
  32.         out.writeRawData(byteTemp, readSize);
  33.         totalCopySize += readSize;
  34.         ui->progressBar_copy->setValue(totalCopySize);
  35.     }
  36.     if(totalCopySize == fileSize){
  37.         tofile.setPermissions(QFile::ExeUser);
  38.         return true;
  39.     }
  40.     else
  41.         return false;
  42. }

阅读(8040) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~