Reply
Thread Tools
Posts: 52 | Thanked: 41 times | Joined on Sep 2010
#1
How can I recieve information about copying progress when using QFile.copy(...) ??? I use it to copy big files on n900, I want to make progress bar indicator. I found nothing on the web about this. Im writing in python but I think I could translate it from C++ If anyone knows the solution. Please help.
 
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#2
Originally Posted by ukaef View Post
How can I recieve information about copying progress when using QFile.copy(...) ??? I use it to copy big files on n900, I want to make progress bar indicator. I found nothing on the web about this. Im writing in python but I think I could translate it from C++ If anyone knows the solution. Please help.
QFile inherits QIODevice, which emits the signal bytesWritten(qint64). The documentation for QIODevice is here: http://www.riverbankcomputing.co.uk/...qiodevice.html

You can use a QProgressBar to display the progress, and use the setValue(int) method to update the progress by connecting that method to the bytesWritten(qint64) signal emitted by the QFile instance, e.g:

Code:
myFile = QFile("path/to/file")
self.progressBar = QProgressBar(self)

self.connect(myFile, SIGNAL("bytesWritten(qint64)"), self.updateProgress)

def updateProgress(self, progress):
""" Updates the progress bar"""
self.progressBar.setValue(progress)
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub

Last edited by marxian; 2010-12-09 at 14:12.
 

The Following 3 Users Say Thank You to marxian For This Useful Post:
Posts: 52 | Thanked: 41 times | Joined on Sep 2010
#3
Help! I cannot get this working... Anyone know what is wrong with my code?
Code:
class Win(QMainWindow):
  def __init__(self):
    QMainWindow.__init__(self)
    (...)
    self.ui=WinUi()
    self.ui.setupUi(self)
  def updateProgress(self, progress):
    self.ui.progressBar.setValue(progress)
    self.ui.label.setText("Please wait, storing file..."+progress)  
    (...)
  def clickchoose(self):
    (...)
  def click(self, place):
    foundone = 0
    for root, dirs, files in os.walk('/home/user/MyDocs/tmp'):
      for file in files:
        foundone = 1
        self.tempFile=QFile('/home/user/MyDocs/tmp/'+files[0])
        self.connect(self.tempFile, SIGNAL("bytesWritten(qint64)"), self.updateProgress)
        (...)
        if fname[0]=="":
          filechk=self.tempFile.copy(place+files[0])
        else:
          filechk=self.tempFile.copy(place+fname[0]+'.flv')
        if filechk==0:
          (...)
No matter what i put into updateProgress it wont work. Its also strange that when I want to change text on QLabel widget BEFORE self.tempFile.copy it will be updated on screen AFTER copying. So I dont know how to indicate that file is copying. PRogressBar would be great, but I dont even know how to display any kind of message before copying. Anyone can help me with this?
 
Reply


 
Forum Jump


All times are GMT. The time now is 01:20.