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. How to read all files from a selected directory and use them one by one?

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

Scheduled Pinned Locked Moved Solved General and Desktop
directorystack of imagesread all filesqdir
6 Posts 4 Posters 89.3k 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.
  • B Offline
    B Offline
    beginMyCoding
    wrote on 4 Mar 2016, 15:02 last edited by beginMyCoding 3 Apr 2016, 15:04
    #1

    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?

    T 1 Reply Last reply 4 Mar 2016, 15:54
    0
    • B beginMyCoding
      4 Mar 2016, 15:02

      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?

      T Offline
      T Offline
      the_
      wrote on 4 Mar 2016, 15:54 last edited by
      #2

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

      -- No support in PM --

      1 Reply Last reply
      6
      • B Offline
        B Offline
        beginMyCoding
        wrote on 8 Mar 2016, 16:59 last edited by beginMyCoding 3 Aug 2016, 17:08
        #3

        @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.

        B 1 Reply Last reply 8 Mar 2016, 17:40
        0
        • B beginMyCoding
          8 Mar 2016, 16:59

          @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.

          B Offline
          B Offline
          beginMyCoding
          wrote on 8 Mar 2016, 17:40 last edited by
          #4

          @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

          A 1 Reply Last reply 20 Jul 2019, 06:26
          0
          • B beginMyCoding
            8 Mar 2016, 17:40

            @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

            A Offline
            A Offline
            AbhishekBlaze
            wrote on 20 Jul 2019, 06:26 last edited by
            #5

            @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

            1 Reply Last reply
            1
            • _ Offline
              _ Offline
              _tan
              wrote on 24 Apr 2020, 15:08 last edited by
              #6

              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.

              1 Reply Last reply
              0

              • Login

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