How to add ftp put function in PyQT network ftp demo

不坏阿峰 onlydebian at gmail.com
Wed Jul 2 10:05:38 CEST 2014


在 2014年7月1日星期二UTC+7下午5时27分59秒,不坏阿峰写道:
> I want to modify the pyqt network ftp demo to include an upload function, but I am failing. Could someone can show me how to do this? I have tried to add this code, but it does not work. 
> 
> [Orignal demo]https://github.com/Werkov/PyQt4/blob/master/examples/network/ftp/ftp.py
> 
> 
> 
> at First, i add these code into demo. not work at all
> 
> ##############
> 
> buttonBox.addButton(self.uploadButton,
> 
>             QtGui.QDialogButtonBox.ActionRole)
> 
> self.uploadButton = QtGui.QPushButton("upload")
> 
> self.uploadButton.clicked.connect(self.selectFile)
> 
> 
> 
> def selectFile(self):
> 
>     self.filename =QtGui.QFileDialog.getOpenFileName()
> 
>     up_fname = re.sub(r".*/","",self.filename)
> 
>     upload_file = QtCore.QFile(self.filename)
> 
>     self.ftp.put(upload_file, up_fname)
> 
> 
> 
> ##############
> 
> 
> 
> Second, i modify like this, i can upload small file successfully, but fail on big size file, the app will crash.
> 
> 
> 
> #####################
> 
>     def selectFile(self):
> 
>         self.filename =QtGui.QFileDialog.getOpenFileName()
> 
>         print self.filename
> 
>         up_fname = re.sub(r".*/","",self.filename)
> 
>         print up_fname
> 
> 
> 
> 
> 
>         upload_file = QtCore.QFile(self.filename)
> 
>         #print upload_file
> 
>         upload_file.open(QtCore.QIODevice.ReadOnly)
> 
>         ba = QtCore.QByteArray()
> 
>         ba.append(upload_file.readAll())
> 
>         
> 
>         #buffer = QtCore.QBuffer()            #### do not how to use Buffer
> 
>         #buffer.open(QtCore.QIODevice.ReadWrite)
> 
>         #buffer.setData(ba)
> 
>         
> 
>         self.ftp.put(ba, up_fname)
> 
>         self.progressDialog.setLabelText("Uploading %s..." % up_fname)
> 
>         self.uploadButton.setEnabled(False)
> 
>         self.progressDialog.exec_()
> 
>         self.uploadButton.setEnabled(True)
> 
>         self.ftp.list()
> 
> 
> 
> ####################

any one can give some suggestion?



More information about the Python-list mailing list