微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用于复制文件的进度条

我正在尝试为Qt中的文件复制创build一个进度条。 这是尽可能接近,但我相信这是行不通的,因为根据Qt类文档:

与其他qiodevice实现(如QTcpsocket)不同,QFile不会发出aboutToClose(),bytesWritten()或readyRead()信号。 这个实现细节意味着QFile不适合读写某些types的文件,比如Unix平台上的设备文件

我怎么能做这样的事情? 我不知道如何实现我自己的信号。

这是我的代码

gcc -O2与无原因错误

WSR显示数字

如何等待被调用进程的克隆subprocess退出

如何得到导致结构exception的模块名称_EXCEPTION_POINTERS结构? (win32 C ++)

如何在Windows中的多个连续模式插入stringc#

void Replicator::anotbaandbFile(QDir source,QDir target) { source.setFilter(QDir::Files | QDir::NodotAndDotDot | QDir::NoSymLinks); target.setFilter(QDir::Files | QDir::NodotAndDotDot | QDir::NoSymLinks); qDebug() << "Scanning: " << source.path(); QStringList sourceFileList = source.entryList(); QStringList targetFileList = target.entryList(); for (int aCount = 0; aCount < sourceFileList.count(); aCount++) { bool found = false; for (int bCount = 0; bCount < targetFileList.count(); bCount++) if (sourceFileList.at(aCount) == targetFileList.at(bCount)) found = true; if (found == false) { sourceFile = new QFile(source.absolutePath()+"/"+sourceFileList.at(aCount)); targetFile = new QFile(target.absolutePath()+"/"+sourceFileList.at(aCount)); progressBar->setMinimum(0); progressBar->setMaximum(sourceFile->size()); written = 0; connect(sourceFile,SIGNAL(bytesWritten(qint64)),SLOT(onWrite(qint64))); sourceFile->copy(targetFile->fileName()); //QFile::copy(source.absolutePath()+"/"+sourceFileList.at(aCount),target.absolutePath()+"/"+sourceFileList.at(aCount)); qDebug() << source.absolutePath()+"/"+sourceFileList.at(aCount) << " " << target.absolutePath()+"/"+sourceFileList.at(aCount); } } }

void Replicator::onWrite(qint64 w) { written += w; progressBar->setValue( written ); }

C错误:free():无效的下一个大小(快):,OSX,Linux上的C程序的不同行为

如果SetForegroundWindow和ShowWindowAsync不起作用,如何设置前景窗口?

在JNI中的jvm-crash调用ReleaseStringUTFChars,只在Windows 7,Windows XP上罚款

在OS X上开始使用C#

在C,C ++中检测Windows或Linux

从上面修改的新代码

if (found == false) { sourceFile = new QFile(source.absolutePath()+"/"+sourceFileList.at(aCount)); targetFile = new QFile(target.absolutePath()+"/"+sourceFileList.at(aCount)); progressBar->setMinimum(0); progressBar->setMaximum(sourceFile->size()); QByteArray buffer; for (int count = 0; !(buffer = sourceFile->read(1000000)).isEmpty(); count+=1000000) { targetFile->write(buffer); progressBar->setValue(count); } //targetFile->write(buffer); //QFile::copy(source.absolutePath()+"/"+sourceFileList.at(aCount),target.absolutePath()+"/"+sourceFileList.at(aCount)); qDebug() << "copying " << sourceFile->fileName() << " to " << targetFile->fileName(); }

您可以简单地复制大文件的固定大小的部分,比计数部分已经复制和工作的百分比通过将其分为几个部分的计数工作。

int iWorkPercentage = (int)(((float)iPortionsprocessed / (float)iOveralPortions) * 100);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐