Results 1 to 2 of 2

Thread: QNetworkReply doesn't abort/close - PyQT

  1. #1
    Join Date
    May 2013
    Posts
    1
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default QNetworkReply doesn't abort/close - PyQT

    My Code: (relevent parts)

    Qt Code:
    1. def update(self):
    2. request = QNetworkRequest()
    3. request.setUrl(QUrl("someurl"))
    4. self.network_manager.finished.connect(self._update)
    5. self.network_manager.get(request)
    6.  
    7. def _update(self, reply): # update stage 2
    8. if not reply.error() == QNetworkReply.NoError:
    9. # request probably failed
    10. print(reply.error())
    11. print(reply.errorString())
    12. print("retrying")
    13. self.update()
    14. else:
    15. reply.abort()
    16. #print(str(reply.readAll().data()))
    17. data = json.loads(str(reply.readAll().data())) # get data
    18. #work with the data (irrelevant)
    19.  
    20. def sendBearer_req(self):
    21.  
    22. request = QNetworkRequest()
    23. request.setUrl(QUrl("someotherurl"))
    24.  
    25. self.network_manager = QNetworkAccessManager()
    26. self.network_manager.finished.connect(self._request_finished)
    27.  
    28. self.network_manager.post(request, self.urlencode_post({'some' : 'thing'}))
    29.  
    30. def sendBearer(self, reply):
    31. reply.abort()
    32. ans = reply.readAll()
    33. print(ans)
    34. time.sleep(5)
    35. print(ans)
    36.  
    37. try:
    38. self.bearer = json.loads(str(ans))
    39. self.update()
    40. except:
    41. raise #for debugging
    42. self.sendBearer_req() #retry
    43.  
    44. def _request_finished(self, reply):
    45. if not reply.error() == QNetworkReply.NoError:
    46. # request probably failed
    47. print(reply.error())
    48. print(reply.errorString())
    49. print("retrying")
    50. self.sendBearer_req()
    51. else:
    52. self.sendBearer(reply)
    To copy to clipboard, switch view to plain text mode 

    Problem:

    in this part:

    Qt Code:
    1. reply.abort()
    2. ans = reply.readAll()
    3. print(ans)
    4. time.sleep(5)
    5. print(ans)
    To copy to clipboard, switch view to plain text mode 

    I'm pretty sure the `abort` isn't working because on the first `print` it prints just what i want but then, while it waits, apparently it continues with the code and enters the `update` function where it sends another request. Therefor in the second `print` the two replies mix together and it prints the both.

    (btw I tried `close` as well - same result)

    What am I doing wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkReply doesn't abort/close - PyQT

    What is the expected behaviour? Why are you calling time.sleep(5)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. the pure virtual method "abort" in QNetworkReply
    By mavenlin in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2011, 11:01
  2. Multi-dialog program in PyQT will not close
    By Danny Hatt in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2010, 23:12
  3. Multi-dialog program in PyQT will not close (the sequel!)
    By Danny Hatt in forum Qt Programming
    Replies: 0
    Last Post: 19th June 2010, 02:05
  4. how to catch close event in this program? [pyqt]
    By pyqt123 in forum Qt Programming
    Replies: 15
    Last Post: 14th December 2009, 12:30
  5. QNetworkReply::abort crash
    By danc81 in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2009, 12:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.