Results 1 to 4 of 4

Thread: Safe to store QFileInfo objects?

  1. #1
    Join Date
    May 2017
    Posts
    6
    Thanked 1 Time in 1 Post

    Default Safe to store QFileInfo objects?

    I came across a post a while back saying that you shouldn't store QFileInfo objects. I can't find the post but I seem to recall that the reason given was related to the caching feature. Reading the QFileInfo documentation it doesn't appear say that QFileInfo objects should not be stored, so I'm not sure if this information was correct.

    I wanted to store information on a large number of files, and was going to store the QFileInfo objects for each file. However, I'm now cornered that this is the wrong thing to do and storing a large number of QFileInfo objects may cause performance issues.

    Is it safe to store QFileInfo objects or would it be better to extract the information I need to a separate class and store that?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Safe to store QFileInfo objects?

    I don't think there is a problem with storing QFileInfo instances. The issues would arise when you read them back in and want to use them. In such a case, I would read it in, then call QFileInfo::refresh() to force a re-caching from the file system, then call QFileInfo::exists() to verify that it still references a valid file.

    But I think it would be far easier to simply store the absolute path of the file, then read that back in to create the QFileInfo instance. You would call QFileInfo::exists() in that case as well. Everything you need from QFileInfo is embodied in the absolute path, since that is usually the way you create them in the first place.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2017
    Posts
    6
    Thanked 1 Time in 1 Post

    Default Re: Safe to store QFileInfo objects?

    The issue you discuss of the cache becoming out of date is probably what that other post was referencing when it recommended not storing QFileInfo objects.

    I was intending to use a QFileSystemWatcher to ensure that the QFileInfo objects were kept up to date, so it sounds like storing the QFileInfo objects should be fine.

    Thanks a lot for your advice.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Safe to store QFileInfo objects?

    I was intending to use a QFileSystemWatcher to ensure that the QFileInfo objects were kept up to date, so it sounds like storing the QFileInfo objects should be fine.
    Then I have no idea what you mean by "storing". I assumed you meant saving persistently in a file, in which case using a QFileSystemWatcher makes no sense.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QFileInfo
    By ishkabible in forum Qt Programming
    Replies: 3
    Last Post: 20th September 2010, 01:08
  2. Replies: 3
    Last Post: 9th January 2010, 16:47
  3. Is there such a way QFileInfo
    By baray98 in forum Qt Programming
    Replies: 9
    Last Post: 21st April 2008, 04:23
  4. about QFileInfo
    By Pang in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2006, 11:09
  5. Replies: 7
    Last Post: 18th July 2006, 22:33

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.