进度条与QFile :: copy()? [英] progress bar with QFile::copy()?

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

问题描述

我正在做一个程序,在Qt中复制文件。我想知道如何使用 QProgressBar bool QFile :: copy(const QString& fileName,const QString& newName)。这是可能的 copy function?复制过程是否可以暂停?


谢谢。

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?

Thank you.

推荐答案

这是使用静态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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆