在 QListview 中异步加载 QICon
我正在使用委托将标准项目模型数据显示到 qt 中的列表视图中。 该模型具有 QIcon 以及标题和子标题字符串。
现在我想通过 http 将远程图像异步加载到列表视图中。 我该怎么做?
我已经运行了列表视图。
I am using a delegate to show a standard item model data into a listview in qt.
The model has a QIcon and a header and subheader strings.
Now i want to load remote images via http into the listview asynchronously.
How can i do this?
I have already got the listview running.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多不同的方法可以解决您的任务,正确的答案取决于您如何构建 ui、它的用途以及应用程序中其他组件的工作方式。不过,这里有一个想法供您考虑:
为您的列表视图创建一个模型,猜测模型的每个项目都应该有一个指向您要下载的图标\图像的链接。
使用QNetworkAccessManager异步连接qt networkManager get
Once an image下载网络管理器的“完成”信号处理程序将被调用,您需要在模型中更新与下载的链接相对应的记录,并使用指向图像对象的指针。
对于列表,您可以使用 项目委托 绘制一个空的尚未下载图标的记录的占位符(或只是默认图像);
确保您正在同步模型 (QMutex < a href="http://doc.trolltech.com/main-snapshot/qsemaphore.html" rel="nofollow noreferrer">QSemaphore QWaitCondition)
希望这有帮助,问候
There are a lot of different ways to solve your task, and correct answer depends on how you're building your ui and what it's meant for and how other components in your application work. Nevertheless, here's an idea for you to consider:
Create a model for your listview, a guess each item of your model should have a link to the icon\image which you're going to download.
Use QNetworkAccessManager to connect to asynchronously download the image via http. Example of you can do this is here: qt networkManager get
Once an image is downloaded network manager's "finished" signal handler will be called, there you need to update a record in your model corresponding to the downloaded link with the pointer to the image object.
For the list you can use an item delegate to draw an empty place holder (or just a default image) for the records which don't have an icon downloaded yet;
Make sure you're synchronizing your model (QMutex QSemaphore QWaitCondition)
hope this helps, regards