Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a folder is writable using Qt

I am trying to check if a folder is writable so I can prompt an error dialog. I am trying this:

QFileDevice::Permissions permissions_list = QFile( folderName ).permissions();

    if ( permissions_list && QFileDevice::WriteUser )
    {
    }

but it does not work. It's the same for both writable folders and restricted ones.

like image 222
azal Avatar asked Feb 10 '16 13:02

azal


1 Answers

use QFileInfo:

QFileInfo my_dir(folderName);

if(my_dir.isDir() && my_dir.isWritable()){
    // Do something
}

but pay attention to this problem if you're on Windows

like image 108
bibi Avatar answered Sep 21 '22 06:09

bibi