#include "func.h" #include "ui_func.h" #include #include void sleep(unsigned int msec) { QTime dieTime = QTime::currentTime().addMSecs(msec); while( QTime::currentTime() < dieTime ) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } func::func(QWidget *parent) : QWidget(parent), ui(new Ui::func) { ui->setupUi(this); } func::~func() { delete ui; } void func::copyFile(const QString &fromFIleName, const QString &toFileName) { qDebug()<progressBar_copy->setValue(0); tofile.setFileName(toFileName); if(!tofile.open(QIODevice::WriteOnly|QIODevice::Text)) qDebug("0000000"); QDataStream out(&tofile); out.setVersion(QDataStream::Qt_5_4); QFile fromfile; fromfile.setFileName(fromFIleName); if(!fromfile.open(QIODevice::ReadOnly)){ qDebug() << "open fromfile failed!!!"; return; } fileSize = fromfile.size(); QDataStream in(&fromfile); in.setVersion(QDataStream::Qt_5_4); //ui->progressBar_copy->setRange(0, fileSize); CRoundProcesseBar pb; pb.setValue(0); pb.show(); pb.setRange(0,100); int f; f=0; while(!in.atEnd()) { int readSize = 0; //读入字节数组,返回读取的字节数量,如果小于4096,则到了文件尾 readSize = in.readRawData(byteTemp, 4096); out.writeRawData(byteTemp, readSize); totalCopySize += readSize; if((totalCopySize-f)>=fileSize/100) { qDebug()<