Results 1 to 3 of 3

Thread: Read all files in directory

  1. #1
    Join Date
    Mar 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Read all files in directory

    Hi,
    I'm learning to use Qt.
    I have to read all XML file existing in a directory.
    The code I wrote works well with a single file, but I would have results about all the directory.

    Could you suggest me the code that I'd have to paste in my .cpp file that allow me to open a QDialog with the choice of the directory and to select a file per time to read?
    Now that piece of code is:
    Qt Code:
    1. bool DomParser::readFile()
    2. {
    3. QString fileName =
    4. QFileDialog::getOpenFileName(this, tr("Open Gate File"),
    5. QDir::currentPath(),
    6. tr("XML Files (*.xml)"));*/
    7. qDebug() << fileName;
    8. if (fileName.isEmpty())
    9. return false;
    10.  
    11. QFile file(fileName);
    12. if (!file.open(QFile::ReadOnly | QFile::Text)) {
    13. QMessageBox::warning(this, tr("SAX Bookmarks"),
    14. tr("Cannot read file %1:\n%2.")
    15. .arg(fileName)
    16. .arg(file.errorString()));
    17. return false;
    18. }
    19. qDebug() << "file opened"; ....
    To copy to clipboard, switch view to plain text mode 
    This, as I explained, allow me to choose the file and read it. Relevant information will be write into another file so I need all info from all files.
    Thank to all.
    Please help me!
    Last edited by anda_skoa; 20th March 2014 at 09:16. Reason: Add missing [code] tags

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Read all files in directory

    QDir particularly QDir::entryList() and a loop

  3. #3
    Join Date
    Mar 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Read all files in directory

    Quote Originally Posted by ChrisW67 View Post
    QDir particularly QDir::entryList() and a loop
    Thanks for your answer.
    But, how could I write the code?

Similar Threads

  1. Replies: 1
    Last Post: 27th December 2012, 06:01
  2. Count files of a directory
    By radu_d in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2012, 03:17
  3. Read FileName from a directory
    By bismitapadhy in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2009, 07:47
  4. Replies: 12
    Last Post: 17th June 2009, 05:34
  5. directory and files
    By rmagro in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2008, 13:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.