PDA

View Full Version : Force Delete a file or folder in Qt



Arshia Aghaei
20th July 2015, 19:31
Hi , How to force delete a file or folder using Qt ??
With administrator permissions ...

ChrisW67
20th July 2015, 21:44
You can delete files and directories with a combination of QFile::remove(), QDir::remove() and QDir::rmdir().

If you require Windows to elevate privileges then you must use the Windows APIs to achieve that.
http://stackoverflow.com/questions/26714673/escalate-privilege-at-runtime-windows-api-c-c

Arshia Aghaei
22nd July 2015, 14:31
You can delete files and directories with a combination of QFile::remove(), QDir::remove() and QDir::rmdir().

If you require Windows to elevate privileges then you must use the Windows APIs to achieve that.
http://stackoverflow.com/questions/26714673/escalate-privilege-at-runtime-windows-api-c-c

Not a better way ?? With a built-in function or class or struct ???

Radek
22nd July 2015, 17:12
AFAIK, no. There is no object in Qt which would pop up a "password" dialog and (if answered correctly) give you root priviledges. Because some apps can do that, there should be a way of writing such object yourself. The object will depend on the operating system (windows, Linus, etc.)

-------------------

[Edit] ChrisW67s link contains a way of doing it under windows.

ChrisW67
22nd July 2015, 21:37
The necessary mechansims/functions are builtin in to every copy of Windows since Vista, they are fully documented, widely used, utterly non-portable, and frankly ugly. They are, nonetheless, the better way because the alternative is that Windows stayed the wide-open malware magnet its original design made it.