(Py)Qt: problem with image downloading
guys
I want to display some images with their captions inQTextEdit
. I have a dictionary with captions and corresponding URLs. The problem is when I post a request with QNetworkAccessManager
and wait for a signal finished(QNetworkReply*)
, I get reply with image only. How can I determine a corresponding caption this image was requested for?
def _init_(self)
manager = QNetworkAccessManager(self);
self.connect(manager, SIGNAL("finished(QNetworkReply*)"), self.add_record)
for record in dict:
manager.get(QNetworkRequest(QUrl(status['caption'])))
def add_rec开发者_StackOverflow中文版ord(self, reply):
img = QImage()
img.loadFromData(reply.readAll())
self.textEdit.textCursor().insertImage(img)
#I don't know at this point for which caption
#I've received this image
#self.textEdit.append(record['text'] + '\n');
Are there any design patterns for this problem? I would appreciate any ideas
Assuming a recent Qt version, the QNetworkReply::request()
will give you a pointer to the QNetworkRequest
that triggered this reply.
So you can access the information you're after with QNetworkRequest::url()
.
精彩评论