Results 1 to 12 of 12

Thread: QFileSystemModel: how can I be notified of directory listing updates?

  1. #1
    Join Date
    Nov 2008
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QFileSystemModel: how can I be notified of directory listing updates?

    Since QFileSystemModel does its work in a separate thread, the desired information from its indices cannot be fully obtained until it is done retrieving all the information; things like sorting or iterating through the directory listing isn't entirely possible until is has finished. I am wondering if it is possible to be notified of when the thread finishes so that i may at that point obtain a complete listing of the designated directory. Currently i can only retrieve the first file or directory within the current directory, but only after revisiting or refreshing the current directory can i get the complete listing.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    Sure it is, you just sort or interate through the contents as the model is updated. Why do you need to wait until it has finished updating?

  3. #3
    Join Date
    Nov 2008
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    Quote Originally Posted by fatjuicymole View Post
    Sure it is, you just sort or interate through the contents as the model is updated. Why do you need to wait until it has finished updating?
    What method are you talking about exactly? I am using a QTreeView, QSortFilterProxyModel for sorting in the tree view, and a QFileSystemModel as the proxy model's source model. For sorting, when i set the root index on the tree view through QTreeView::setRootIndex(), and then call QTreeView::sortByColumn(), it does not entirely sort the way i want it to except only after re-setting the root index. Likewise, QTreeView::resizeColumnToContents() doesn't show any effect until re-setting.

    And when it comes to obtaining the directory listing from the file system model through QFileSystemModel::index() (the one that takes/can take three parameters), it only ever returns the first file/directory, no other file/directory. However, as mentioned, i can obtain the complete directory listing using the very same methods when attempting to access the same directory a second time. For these reasons, i feel i require being informed of the thread finishing in order to obtain the desired result.

  4. #4
    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: QFileSystemModel: how can I be notified of directory listing updates?


  5. #5
    Join Date
    Nov 2008
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    Quote Originally Posted by ChrisW67 View Post
    Unfortunately, that method is part of my code and bears the same effect.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    What "same effect" are you referring to?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Nov 2008
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    Quote Originally Posted by wysota View Post
    What "same effect" are you referring to?
    Concerning sorting, that would be the tree view listing doesn't sort the way i want it to (first by name, then by type). But sorting is of lower concern, as the user can just click the column headers to sort things their way. I can have everything working the way i want it to if i can delay calling the aforementioned methods till the file system model has finished generating all the information. I would rather avoid using QDir::entryList() as the file system model would already have the information i'm interested in.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    Quote Originally Posted by truefusion View Post
    if i can delay calling the aforementioned methods
    Which methods? setDynamicSortFilter()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    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: QFileSystemModel: how can I be notified of directory listing updates?

    I think the reference is to QTreeView::sortByColumn() but I am still having trouble seeing a problem that needs solving. For example, this works just fine for me;
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QFileSystemModel f;
    8. f.setRootPath("/");
    9.  
    10. proxy.setSourceModel(&f);
    11. proxy.setDynamicSortFilter(true);
    12.  
    13. t.setModel(&proxy);
    14. t.sortByColumn(0, Qt::DescendingOrder);
    15. QModelIndex idx = proxy.mapFromSource(f.index("/usr/include"));
    16. t.setRootIndex(idx);
    17. t.show();
    18.  
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    Even on large folders the files are always sorted correctly.

  10. #10
    Join Date
    Nov 2008
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    Quote Originally Posted by wysota View Post
    Which methods? setDynamicSortFilter()?
    QTreeView::sortByColumn(), QFileSystemModel::index() and QTreeView::resizeColumnToContents().

    Quote Originally Posted by ChrisW67 View Post
    I think the reference is to QTreeView::sortByColumn() but I am still having trouble seeing a problem that needs solving. For example, this works just fine for me;
    [...]
    Even on large folders the files are always sorted correctly.
    After testing out your code, i figured out the problem with mine concerning sorting. Apparently, f->setRootPath(QDir::currentPath()) doesn't allow sorting the first time around (though this example is found in the documentation). Also, the test showed that setDynamicSortFilter() is irrelevant to the sorting and that resizeColumnToContents() does not resize the column properly. I'm still left with my other problem: i can't get a complete directory listing from the file system model the first time around.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    Quote Originally Posted by truefusion View Post
    i can't get a complete directory listing from the file system model the first time around.
    Because you are calling the code too early. Qt models tell you when something changes in them and you either have to react on each of the changes of detect when the model stops signalling you that it is changing. Of course nothing guarantees that it will not change a second later but you can't solve it with resizeColumnToContents() anyway That's why we have QHeaderView::ResizeToContents resize mode
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Nov 2008
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileSystemModel: how can I be notified of directory listing updates?

    Quote Originally Posted by wysota View Post
    Because you are calling the code too early. Qt models tell you when something changes in them and you either have to react on each of the changes of detect when the model stops signalling you that it is changing. Of course nothing guarantees that it will not change a second later but you can't solve it with resizeColumnToContents() anyway That's why we have QHeaderView::ResizeToContents resize mode
    I know it is because i'm calling it too early. But i got it to work with the layoutChanged() signal of the model, though i would prefer for the signal to be emitted once.

    And thanks for informing me about that enum.

Similar Threads

  1. Replies: 1
    Last Post: 28th October 2008, 12:14
  2. How to be notified when a child changes?
    By mooreaa in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2008, 13:04
  3. listing derectory contents
    By ramamurthy.kv in forum Qt Programming
    Replies: 9
    Last Post: 5th May 2008, 19:59
  4. Replies: 5
    Last Post: 4th November 2007, 11:35
  5. listing the files that has been uploaded to postgres
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2007, 10:43

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.