(Py)Qt:图像下载问题

时间:2011-05-17 23:21:18

标签: python qt pyqt pyqt4 image-loading


我想在QTextEdit中显示一些带有标题的图片。我有一个带字幕和相应网址的字典。问题是,当我使用QNetworkAccessManager发布请求并等待信号finished(QNetworkReply*)时,我只会回复图片。如何确定请求此图像的相应标题?

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');

这个问题有没有设计模式?我很感激任何想法

1 个答案:

答案 0 :(得分:2)

假设最近的Qt版本,QNetworkReply::request()将为您提供指向触发此回复的QNetworkRequest的指针。

因此,您可以使用QNetworkRequest::url()访问您所拥有的信息。