Results 1 to 3 of 3

Thread: Display files of a Directory

  1. #1
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Display files of a Directory

    hi to everyone,
    i'm a newbie of programming Qt (using 4.4.3 on a Unix system) .....can anyone tell me the easy way to display Files of a specific dir?
    i search on the forum but i readed something about QDir and QTreeView but i don't find anything reguarding them

    An example will be very appreciated.

    Thanks to everyone

  2. #2
    Join Date
    Mar 2009
    Location
    Belchatow, Poland
    Posts
    38
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Display files of a Directory

    There's an example in QDir Class Reference:


    A program that lists all the files in the current directory (excluding symbolic links), sorted by size, smallest first:
    Qt Code:
    1. #include <QDir>
    2. #include <iostream>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication app(argc, argv);
    7. QDir dir;
    8. dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    9. dir.setSorting(QDir::Size | QDir::Reversed);
    10.  
    11. QFileInfoList list = dir.entryInfoList();
    12. std::cout << " Bytes Filename" << std::endl;
    13. for (int i = 0; i < list.size(); ++i) {
    14. QFileInfo fileInfo = list.at(i);
    15. std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
    16. .arg(fileInfo.fileName()));
    17. std::cout << std::endl;
    18. }
    19. return 0;
    20. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Display files of a Directory

    Look at the Directory View example. It uses QDirModel. The simplest way would be:
    Qt Code:
    1. QTreeView * treeView = new QTreeView(this);
    2. QDirModel * dirModel = new QDirModel(this);
    3. treeView->setModel(dirModel);
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. The following user says thank you to faldzip for this useful post:

    mansu (8th March 2009)

Similar Threads

  1. install help nedded.
    By aj2903 in forum Installation and Deployment
    Replies: 9
    Last Post: 13th November 2008, 07:57
  2. How to display hidden files ?
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2008, 12:27
  3. Display a file from Directory tree to show in QTextEdit
    By vvdounai in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2007, 13:43
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.