(Py)Qt:图像下载问题
伙计们
我想在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设使用最新的 Qt 版本,
QNetworkReply::request()
< /a> 将为您提供一个指向触发此回复的QNetworkRequest
的指针。因此,您可以使用
QNetworkRequest::url()< 访问所需的信息/代码>
。
Assuming a recent Qt version, the
QNetworkReply::request()
will give you a pointer to theQNetworkRequest
that triggered this reply.So you can access the information you're after with
QNetworkRequest::url()
.