PDA

View Full Version : File operations



MTK358
12th September 2010, 23:09
Why do you always have to have a QDir object to add/remove files and dirs? Wouldn't it be far easier to use when file operations were static methods and the QDir object would only be for holding the items, name, info, etc.?

Lykurg
12th September 2010, 23:24
QDir::remove() uses QFile::remove() which is static, but it creates a local QFile, so you won't gain anything. Why they are not static is probably because they need the functionality of QDir/QFile to run some tests before deleting and do the deleting stuff itself. And if the Trolls could have made them static, they surely would have...

squidge
13th September 2010, 00:00
It's probably because the trolls wanted to keep file i/o stuff in the relevent File Engine, making it easier for things like QDir to work on totally different platforms without having to change the actual implementation.

wysota
13th September 2010, 00:04
I'd say one could treat the relevant api from QDir as an overload of the same api from QFile with that difference that it is meant to operate on relative file names. If one has QFile::remove() that is static, there is no point in having the same static operation in another class.