
我正在尝试为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);
总结以上是内存溢出为你收集整理的用于复制文件的进度条全部内容,希望文章能够帮你解决用于复制文件的进度条所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)