Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move files to Trash/Recycle Bin in Qt

Is there a Qt function to move files to Recycle Bin instead of truly deleting them, for OSes that support it, or do I need to use OS-specific code?

like image 215
sashoalm Avatar asked Jul 31 '13 07:07

sashoalm


People also ask

Why can't I move a file to the Recycle Bin?

If you delete a file with a size bigger than the Recycle Bin limit, it won't go into the bin. On your desktop, right-click the Recycle Bin icon and then click Properties. When the Recycle Bin dialog box pops up, ensure that the radio button under Settings for selected location is on Custom size.

Does moving to Recycle Bin delete files?

Whenever you delete a file in your computer and empty your Recycle Bin, your data is not entirely wiped out from your computer. Although you can no longer see the file on the location it once was and your operating system no longer has it, a copy of it still exists in your hard drive.


1 Answers

Since Qt 5.15.0 Alpha, this method has been added, which should be what you were looking for.

bool QFile::moveToTrash()

The corresponding code changes can be found here.

(This issue is old and the corresponding Bugreport at https://bugreports.qt.io/browse/QTBUG-47703 has already been posted, but I currently lack the reputation to comment, and found this to be a useful information.)

like image 117
darthn Avatar answered Oct 14 '22 03:10

darthn