Results 1 to 5 of 5

Thread: Create a private directory under user

  1. #1
    Join Date
    Mar 2009
    Posts
    39
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Create a private directory under user

    I want to create a simple directory in under QDir::homePath() but that is only readable by the owner (active user). Using QDir::mkdir creates it but is visible, its contents is accessible to other users (at least under Mac)

    What would be the most portable procedure to create a private folder?, I've been making some attemps opening the new dir as a QFile and using setPermissions but it looks like doesnt change anything, would be this the correct route?

    Thanks!

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Create a private directory under user

    hi,

    So this:

    Qt Code:
    1. QDir dir;
    2. dir.setCurrent(dir.homePath());
    3. dir.mkdir("FromQT");
    To copy to clipboard, switch view to plain text mode 

    Will create a directory in your Mac home that is accessible by other?

    Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise the path returned by the rootPath()

    rootPath: For Unix operating systems this returns "/". For Windows file systems this normally returns "c:/".

    Check if you get a proper path for homePath().

    Carlos.

  3. #3
    Join Date
    Mar 2009
    Posts
    39
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Create a private directory under user

    Quote Originally Posted by qlands View Post
    So this:

    Qt Code:
    1. QDir dir;
    2. dir.setCurrent(dir.homePath());
    3. dir.mkdir("FromQT");
    To copy to clipboard, switch view to plain text mode 

    Will create a directory in your Mac home that is accessible by other?
    Yes, I've copypasted your code and it created Macintosh HD/Users/me/FromQT and I can get into and read from another user -non admin-. ReadOnly, it can not write though. I guess these are the default permissions.

    Somehow replying to my first question, I will create the folders on
    Qt Code:
    1. QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)
    To copy to clipboard, switch view to plain text mode 
    so they go into a directory already fully protected and it looks like it will keep the disk more clean.

    Thanks,
    Juan

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Create a private directory under user

    Did you try like this?
    Qt Code:
    1. if(file.setPermissions(QFile::ReadOwner|QFile::WriteOwner)){
    2. qDebug() << "Permissions changed";
    3. } else {
    4. qDebug() << "Couldn't change permissions";
    5. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Posts
    39
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Create a private directory under user

    Quote Originally Posted by wysota View Post
    Did you try like this?
    Qt Code:
    1. if(file.setPermissions(QFile::ReadOwner|QFile::WriteOwner)){
    2. qDebug() << "Permissions changed";
    3. } else {
    4. qDebug() << "Couldn't change permissions";
    5. }
    To copy to clipboard, switch view to plain text mode 
    Yes, I tried but I did witht the file open and didn't work (setPermissions was returning true but the actual permissions didn't change).
    I've just tried not opening the file and it woks perfectly.
    Thanks!

Similar Threads

  1. How to create a directory with hidden attribute
    By sanjayshelke in forum Qt Programming
    Replies: 6
    Last Post: 8th November 2012, 13:09
  2. how to create shortcut to a directory
    By kamlmish in forum Newbie
    Replies: 1
    Last Post: 28th January 2011, 05:18
  3. Replies: 3
    Last Post: 11th September 2008, 20:08
  4. How to create a symlink to a directory?
    By ucomesdag in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2007, 19:01
  5. create file in another directory
    By raphaelf in forum Qt Programming
    Replies: 3
    Last Post: 16th February 2006, 10:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.