Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Navigate through images within a directory in an efficient way?
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?
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.
Hi and welcome to devnet,
Are you using a "QFileSystemModel":http://qt-project.org/doc/qt-5/qfilesystemmodel.html ?