QFile::copy() 的进度条?

Progress bar with QFile::copy()?(QFile::copy() 的进度条?)
本文介绍了QFile::copy() 的进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个在 Qt 中复制文件的程序.我想知道如何将 QProgressBarbool QFile::copy(const QString & fileName, const QString & newName) 一起使用.这甚至可以通过 copy 功能实现吗?复制过程可以暂停吗?

I'm making a program which copies files in Qt. I want to know how can I use QProgressBar with bool QFile::copy(const QString & fileName, const QString & newName). Is this even possible with copy function? Can the process of copying be paused?

推荐答案

使用静态 QFile::copy() 方法无法做到这一点.

You can't do this using the static QFile::copy() method.

正如 Maciej 在您需要编写自己的课程之前所说的那样.它应该使用两个 QFile 对象,一个用于读取,一个用于写入.分部分传输数据(例如,整个文件大小的 1%)并在每个部分之后发出进度信号.您可以将此信号连接到进度对话框.

As Maciej stated before you need to write your own class. It should use two QFile objects, one for reading one for writing. Transfer the data in portions (e.g 1% of the entire file size) and emit a progress signal after each portion. You can connect this signal to a progress dialog.

如果你需要它在后台工作,你应该使用 QThread 来实现它.

If you need this to work in the background you should implement it using a QThread.

首先尝试确定您是否需要一个异步(不阻塞 GUI)或同步(阻塞 GUI)复制工作的类.后者更容易编程,但大多数时候不是预期的(例如,如果 GUI 被阻止,您不能通过单击按钮取消或暂停复制操作).

First try to decide if you need a class that does the copy work asynchonously (without blocking the GUI) or synchronously (blocking the GUI). The latter is easier to programming but most times not what is intended (e.g. you can not cancel or pause a copy operation by button click if the GUI is blocked).

你可以在这里查看一个相当广泛的 Qt 4 类:http://docs.huihoo.com/qt/solutions/4/qtcopydialog/qtfilecopier.html 但由于其复杂性,我不确定这是否会有所帮助.

You can have a look here for a pretty extensive Qt 4 class: http://docs.huihoo.com/qt/solutions/4/qtcopydialog/qtfilecopier.html but I am not sure if this will help due to its complexity.

这篇关于QFile::copy() 的进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)