c++qtcross-platformrecycle-bin

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?


Solution

  • 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.)