2

guys
I want to display some images with their captions in QTextEdit. 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_record(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

nikagra
  • 835
  • 2
  • 9
  • 23

1 Answers1

2

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().

Mat
  • 202,337
  • 40
  • 393
  • 406
  • And using url I can determine caption for it in my dict. Thanks a lot! – nikagra May 18 '11 at 09:24
  • There is a problem. I may store the same url's in the dict, thats why multiple captions will be displayed for one image – nikagra May 18 '11 at 15:06
  • It's possible to attach originating object to the request by `setOriginatingObject(QObject)`, but how can cast long or str to QObject? Why does it dont work to `setOriginatingObject(QString)`? – nikagra May 18 '11 at 15:42
  • @nikagra: this question requested to get the caption from the request. I believe you got that. Now you have a different question - so open a new question. – Mat May 18 '11 at 15:44