How to read all files from a selected directory and use them one by one?



  • Hi
    My main aim is to open a window to display some images of same size as a stack of images(sequence of images) and place a scroll 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?



  • @beginMyCoding

    Have a look at QDir::entryList()
    This returns you a QStringList with the entries in the selected directory

    For 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 :) )



  • @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 and label(display window) with SLIGNAL and SLOTS such that when i scroll the slider the image should change.
    Any ideas of doing this?

    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.



  • @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 of horizontalslider



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.