<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif; "><div><div>You need to keep the handle to your QFile object in scope. The put() method returns straight away and the data to be put is added to a queue and uploaded in the background. Your selectFile() method returns straight away therefore your upload_file object goes out of scope before it can be sent. Simply changing upload_file to self.upload_file will solve your problem.</div></div><div><br></div><div>Hope this helps ;o)</div><div>Rob</div><div><br></div><div><br></div><span id="OLK_SRC_BODY_SECTION"><div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt"><span style="font-weight:bold">From: </span> 不坏阿峰 <<a href="mailto:onlydebian@gmail.com">onlydebian@gmail.com</a>><br><span style="font-weight:bold">Date: </span> Tuesday, 1 July 2014 03:30<br><span style="font-weight:bold">To: </span> <<a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a>><br><span style="font-weight:bold">Subject: </span> [PyQt] How to add ftp put function in PyQT network ftp demo<br></div><div><br></div><div dir="ltr"><span style="color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.804800033569336px; ">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]</span><a href="https://github.com/Werkov/PyQt4/blob/master/examples/network/ftp/ftp.py" rel="nofollow" style="margin:0px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;color:rgb(74,107,130);text-decoration:none;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">https://github.com/Werkov/PyQt4/blob/master/examples/network/ftp/ftp.py</a><br><div><br></div><div><pre class="" style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;color:rgb(0,0,0);line-height:17.804800033569336px;background:rgb(238,238,238)"><code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:inherit;background-image:initial;background-repeat:initial"><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">buttonBox</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">addButton</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">uploadButton</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">,</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">
            </span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">QtGui</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">QDialogButtonBox</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">ActionRole</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">)</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">
self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">uploadButton </span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">=</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent"> </span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">QtGui</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">QPushButton</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(128,0,0);background:transparent">"upload"</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">)</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">
self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">uploadButton</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">clicked</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">connect</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">selectFile</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">)</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent"></span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(0,0,139);background:transparent">def</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent"> selectFile</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">):</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">
    self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">filename </span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">=</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">QtGui</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">QFileDialog</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">getOpenFileName</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">()</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">
    up_fname </span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">=</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent"> re</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">sub</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">r</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(128,0,0);background:transparent">".*/"</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">,</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(128,0,0);background:transparent">""</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">,</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">filename</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">)</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">
    upload_file </span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">=</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent"> </span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">QtCore</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;color:rgb(43,145,175);background:transparent">QFile</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">filename</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">)</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">
    self</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">ftp</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">.</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">put</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">upload_file</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">,</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent"> up_fname</span><span class="" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;background:transparent">)</span></code></pre></div></div>
_______________________________________________
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></span></body></html>