Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Navigate through images within a directory in an efficient way?
Forum Update on Monday, May 27th 2025

Navigate through images within a directory in an efficient way?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 829 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sigsegv
    wrote on 13 Dec 2014, 20:53 last edited by
    #1

    I'm making an image viewer app and I need to let the user go back and forth from one image to its next/previous, but I'm unable to find an efficient way to do so.

    I'm currently storing all image file paths using the "entryList" call from "QDir" and iterating through the resulting "QStringList", but filling the list is an awfully slow operation when the directory contains a large number of files. In fact, I don't actually need to store all image entries, since the user won't view more than one image at a time.

    Any ideas on how can I implement the "next/previous" functions avoiding the use of potentially slow operations?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 13 Dec 2014, 23:05 last edited by
      #2

      One way to deal with this is to use QDirIterator in a worker thread and fill the list in the background one by one while the main thread can start to display images. Of course access to the list must be performed in a thread-safe manner e.g. mutex or a signal to the main thread to add another item.

      As for the images themselves, to make them snappy you should open lets say 5 at once - the current one, 2 previous and 2 next. When image is switched to the next unload the second previous and load new next. This way when the user requests previous/next image showing it will be instantaneous. Loading can also be done in a worker thread if the images take long to load.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 13 Dec 2014, 23:06 last edited by
        #3

        Hi and welcome to devnet,

        Are you using a "QFileSystemModel":http://qt-project.org/doc/qt-5/qfilesystemmodel.html ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        3/3

        13 Dec 2014, 23:06

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved