PDA

View Full Version : Check file is modified?



mamyte03@gmail.com
19th September 2007, 15:13
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


void FileWidget::on_openButton_clicked()
{
QString id=lineEdit->text();
QString failas=lineEdit_2->text()+"."+typeEdit->text();
QString tempFile=QDir::tempPath()+"/"+id+failas;

QFile f(tempFile);
f.open(QIODevice::WriteOnly);
f.write(record->getValue("file", "content").toByteArray());
f.close();

QFileInfo info(tempFile);
firstDate=info.lastModified();

QDesktopServices::openUrl(QUrl::fromLocalFile(temp File));


//qDebug()<<firstDate;

marcel
19th September 2007, 15:29
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.

mamyte03@gmail.com
19th September 2007, 15:36
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

marcel
19th September 2007, 15:46
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.

mamyte03@gmail.com
19th September 2007, 15:51
but how can I start and check when I finished the work with file?

wysota
19th September 2007, 17:03
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.

ghorwin
20th September 2007, 14:03
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.