How to read all files from a selected directory and use them one by one?
-
wrote on 4 Mar 2016, 15:02 last edited by beginMyCoding 3 Apr 2016, 15:04
Hi
My main aim is to open a window to display some images of same size as astack of images
(sequence of images) and place ascroll bar
such that when i move the scroll bar the image is displayed accordingly from the stack.My idea of doing this is store all the image files from the selected
directory
(folder) and use one image at a time to display when i move the scroll bar.I tried something like this
QDir directory = QFileDialog::getExistingDirectory(this, tr("select directory")); list = QDir::Files(directory); fileName = list(1);
but this is a wrong thing. Does anyone developed something of this sort? or anyother ideas how this can be done?
-
Hi
My main aim is to open a window to display some images of same size as astack of images
(sequence of images) and place ascroll bar
such that when i move the scroll bar the image is displayed accordingly from the stack.My idea of doing this is store all the image files from the selected
directory
(folder) and use one image at a time to display when i move the scroll bar.I tried something like this
QDir directory = QFileDialog::getExistingDirectory(this, tr("select directory")); list = QDir::Files(directory); fileName = list(1);
but this is a wrong thing. Does anyone developed something of this sort? or anyother ideas how this can be done?
wrote on 4 Mar 2016, 15:54 last edited byHave a look at QDir::entryList()
This returns you a QStringList with the entries in the selected directoryFor Example
//assume the directory exists and contains some files and you want all jpg and JPG files QDir directory("Pictures/MyPictures"); QStringList images = directory.entryList(QStringList() << "*.jpg" << "*.JPG",QDir::Files); foreach(QString filename, images) { //do whatever you need to do }
(Maybe there are better solutions, this one should work too :) )
-
wrote on 8 Mar 2016, 16:59 last edited by beginMyCoding 3 Aug 2016, 17:08
@the_ Thanks a lot, this idea really worked well to store the filenames and use them.
Do you know how to set the maximum(value) for the scroll bar? I want to assign the length of QStringList to be the maximum of scroll bar.
QStringList images = directory.entryList(QStringList() << "*.jpg" << "*.JPG",QDir::Files); int stack = images.length(); QScrollBar.setMaximum(stack);
but i have errors. I want to connect
horizontalSlider
andlabel
(display window) withSLIGNAL and SLOTS
such that when i scroll the slider the image should change.
Any ideas of doing this?one last question:
ifQStringList images
has 10 fileNames, is it possible to access a particular fileName
such asimages(5) or images(9)
?
i am able to access the first and last fileName withimages.first()
orimages.last()
but not the ones which are in between. -
@the_ Thanks a lot, this idea really worked well to store the filenames and use them.
Do you know how to set the maximum(value) for the scroll bar? I want to assign the length of QStringList to be the maximum of scroll bar.
QStringList images = directory.entryList(QStringList() << "*.jpg" << "*.JPG",QDir::Files); int stack = images.length(); QScrollBar.setMaximum(stack);
but i have errors. I want to connect
horizontalSlider
andlabel
(display window) withSLIGNAL and SLOTS
such that when i scroll the slider the image should change.
Any ideas of doing this?one last question:
ifQStringList images
has 10 fileNames, is it possible to access a particular fileName
such asimages(5) or images(9)
?
i am able to access the first and last fileName withimages.first()
orimages.last()
but not the ones which are in between.wrote on 8 Mar 2016, 17:40 last edited by@beginMyCoding found the solution for
one last question: if QStringList images has 10 fileNames, is it possible to access a particular fileName such as images(5) or images(9)? i am able to access the first and last fileName with images.first() or images.last() but not the ones which are in between.
But waiting for the solution to set
maximum
ofhorizontalslider
-
@beginMyCoding found the solution for
one last question: if QStringList images has 10 fileNames, is it possible to access a particular fileName such as images(5) or images(9)? i am able to access the first and last fileName with images.first() or images.last() but not the ones which are in between.
But waiting for the solution to set
maximum
ofhorizontalslider
wrote on 20 Jul 2019, 06:26 last edited by@beginMyCoding Did you tried the at() ? you can get the particular element at a specific position from QStringList using at()
for example , in your code
images.at(index) will give the element
-
wrote on 24 Apr 2020, 15:08 last edited by
did you figure out how to make this program work? if so, please provide details on it because I am trying to do the same thing with a current project.