Results 1 to 3 of 3

Thread: How to check a file for changes since last save

  1. #1
    Join Date
    Apr 2007
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default How to check a file for changes since last save

    I am making a music app, where the main file format the user can save to is a Song. When the user tries to start or open a new song, I want to check first whether the current song has been changed, and warn the user if it has. My question is, what is the best way to check for changes to a file?

    The most obvious way I can think of is have a "changed" flag in Song objects, which gets flagged every time some operation is performed on the Song. Then when you need to check, you just check the flag.

    I'm wondering if this is the best way? It seems like it could be cumbersome, if every single action that can change a song will need to remember to set the changed flag when it gets called. The number of actions could be pretty large. It feels like it would be nice if I could abstract it out so actions don't have to worry about the changed flag, they can just perform the action.

    I'd love to hear how others have done it in their apps and any general tips
    Qpsycle -- open-source modular music studio built with Qt

  2. #2
    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: How to check a file for changes since last save

    The "proper" way to do it would be to use the undo functionality Qt offers and have two things done at the same time. The down side is that you'd have to implement commands for all things you do in your application.

    The "second proper" way would be to use QWidget's "windowModified" property. Of course you'd have to check the flag yourself everytime you change the document.

    If the object is not a widget, then you have to do it the way you suggested.

  3. The following user says thank you to wysota for this useful post:

    nmather (21st April 2007)

  4. #3
    Join Date
    Apr 2007
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: How to check a file for changes since last save

    Thanks, I didn't know about the Qt Undo framework! That would be ideal.

    Unfortunately the song file object isn't a widget -- it needs to be separated from Qt as it has to work with other applications, using other toolkits.

    However, I wonder if I could write a Qt wrapper for this object that could then utilize the undo framework...
    Qpsycle -- open-source modular music studio built with Qt

Similar Threads

  1. read file from end to beginning..
    By soul_rebel in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2012, 01:20
  2. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10
  3. Reverse Order on QStringList slow...?
    By patrik08 in forum Qt Programming
    Replies: 24
    Last Post: 21st February 2007, 09:32
  4. Check for compressed .qm file?
    By ksierens in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2006, 19:52
  5. What does "Save All" actually save?
    By Mariane in forum Newbie
    Replies: 7
    Last Post: 31st January 2006, 13:23

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.