PDA

View Full Version : QFile::remove() strange refresh problem in windows desktop



ramazangirgin
7th December 2010, 07:01
Hi all,
I'm working on windows 7 with qt 4.6.
I'm doing batch operations on file and then deleting files. I'm using QFile::remove() for deleting each file.
For files which user desktop when deleting files ,files were deleted but in windows explorer files are still on desktop. When i refresh(F5) user desktop files are disappeared.

But for files which in folder this is not occured and all files deleted immediately.

Is there any way to solve this problem or refresh user desktop with code ?

Thanks in advance

Ramazan Girgin

franz
7th December 2010, 07:19
Is that of concern to the program deleting the files?

Timoteo
7th December 2010, 08:29
See SHGetSpecialFolderLocation (http://msdn.microsoft.com/en-us/library/bb762203(VS.85).aspx), SHChangeNotify (http://msdn.microsoft.com/en-us/library/bb762118(VS.85).aspx). You have the pieces to form a solution now.

The reason why this happens is that QFile::remove() is implemented with DeleteFile() in Windows. DeleteFile() is what is used to implement the crt itself, and does not post any notification to the shell.

Lesiok
7th December 2010, 12:55
This problem occurs with many other applications, not only Qt. Bad Windows constructions.

Timoteo
8th December 2010, 00:04
No, it is not the fault of Windows in this case. Windows provides an api subset for interaction with "special folders" (such as the desktop) which is Shell API. I'm assuming that Trolltech chose not to use the Shell API because DeleteFile() is basically guaranteed to exist because of the c runtime's dependency on it (as well as other legacy api code) and the Shell API suffers a break between XP and Windows 7 with file operations. Interacting with a folder that has special significance to the shell without using the shell api is what is bad. So, if you don't like the behavior, it is time to bust out some winapi.

squidge
8th December 2010, 01:04
TBH, since you can register file/dir notifications with the shell, I kinda expected the shell to use that itself so that when someone modifies a folder, regardless of where it is, it refreshes the open windows that are showing that directory.

Every app can see special directories like "Desktop", but I don't think any of the applications I have treat it any differently than any other dir.

Timoteo
8th December 2010, 02:42
You mean you can register your app to receive file notifications from the shell, right? The context of "someone" is very important. If "someone" is the typical user, then they used the shell to make the modifications so the shell already knows about it. If "someone" is a program written with the standard library for file IO, then the shell will know when it is asked to check. If "someone" is a program written against the shell api, then the shell will know just as if the user himself had done it.

but I don't think any of the applications I have treat it any differently than any other dir.
It comes down to whether or not it is suitable for the shell to wait until it is asked by the user (or another process) to refresh the desktop. Also it is worth mentioning that for most purposes the shell api is overkill for file operations.