Results 1 to 7 of 7

Thread: Check file is modified?

  1. #1
    Join Date
    Sep 2007
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Check file is modified?

    I have this type of problem. On printWidget with printDialog inserting file in database. Opening (putting on QDir::tempPatch() )it I can it edit and so on. On save I am checkink modified date. But now I need to open file (for example *doc) , close my printWidget, open for example serviceOrderWidget, close it, go to my opened *doc file, editing it, and saving. When the my program need to ask me want i to save edited file.
    How can i check is this program(file with *.doc) closed? Now i opening it
    Qt Code:
    1. void FileWidget::on_openButton_clicked()
    2. {
    3. QString id=lineEdit->text();
    4. QString failas=lineEdit_2->text()+"."+typeEdit->text();
    5. QString tempFile=QDir::tempPath()+"/"+id+failas;
    6.  
    7. QFile f(tempFile);
    8. f.open(QIODevice::WriteOnly);
    9. f.write(record->getValue("file", "content").toByteArray());
    10. f.close();
    11.  
    12. QFileInfo info(tempFile);
    13. firstDate=info.lastModified();
    14.  
    15. QDesktopServices::openUrl(QUrl::fromLocalFile(tempFile));
    16.  
    17.  
    18. //qDebug()<<firstDate;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Check file is modified?

    You can't check if it's closed if you open it with QDesktopServices.
    However, if the file is open, the big majority of applications sees that the file is already open and asks the user if they should update the file with the modified one, on disk.

  3. #3
    Join Date
    Sep 2007
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Check file is modified?

    Asking programs as word and so on. By I need that word asking, and when i finishing work with word, my program check was file modified, if yes - show QMessageBox and ask - want i to save the data. If i pressing yes, when program my modified *doc file have to update to database

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Check file is modified?

    Then you should check the last modification date of the file. You can save it in the database, along with the file and query for it later.

  5. #5
    Join Date
    Sep 2007
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Check file is modified?

    but how can I start and check when I finished the work with file?

  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: Check file is modified?

    Maybe QFileSystemWatcher can help you? If you're using Qt Commercial with Windows it's also an option to control Word through its COM interface.

  7. #7
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check file is modified?

    mamyte03, I take it you are not only interested in seeing when or if the file was actually modified, but when the work on it is done (work = file is open in Word). Is that right?

    So you essentially need to know when the file gets closes in Word. I fear this can only be done going pretty low-level, either COM or via the Windows API. ASFAIK Qt doesn't provide this functionality to communicate with other applications.

    However, there might be a trick that could work. Word normally marks files that are worked on as read-only, so you will only be able to open the file in read-only mode, as long as the file is open in word. That, in combination with checking the last modified date, should probably give you the information you need.
    Andreas

Similar Threads

  1. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  2. How to check a file for changes since last save
    By nmather in forum General Programming
    Replies: 2
    Last Post: 21st April 2007, 23:43
  3. Retrieving modified date of file using QHttp
    By hardgeus in forum Qt Programming
    Replies: 9
    Last Post: 3rd December 2006, 23:20
  4. Check if a file has been modified
    By Dark_Tower in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 21:27
  5. How to link modified file
    By awalesminfo in forum Newbie
    Replies: 4
    Last Post: 22nd March 2006, 17:24

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.