(Py)Qt:图像下载问题

发布于 2024-11-07 21:20:49 字数 698 浏览 0 评论 0原文

伙计们
我想在 QTextEdit 中显示一些带有标题的图像。我有一本带有标题和相应网址的字典。问题是,当我使用 QNetworkAccessManager 发布请求并等待信号完成(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');

有没有针对这个问题的设计模式?我将不胜感激任何想法

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2024-11-14 21:20:49

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文