开发者

loading QICon asynchronously in QListview

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 listvi开发者_StackOverflowew running.


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:

  1. 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.

  2. Use QNetworkAccessManager to connect to asynchronously download the image via http. Example of you can do this is here: qt networkManager get

  3. 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.

  4. 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;

  5. Make sure you're synchronizing your model (QMutex QSemaphore QWaitCondition)

hope this helps, regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜