Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Navigate through images within a directory in an efficient way?

    General and Desktop
    3
    3
    708
    Loading More Posts
    • 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
      Sigsegv last edited by

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • First post
            Last post