Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to make a folder non writable
Forum Updated to NodeBB v4.3 + New Features

how to make a folder non writable

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    Hi
    I have a need to make a folder non writable
    I have made a QFile object and set the permissions to 0 but I am still able to perform a mkpath operation

    		QFile file(dir.path());
    		QString s = file.fileName();
    		QFile::Permissions permissions = file.permissions();
    		QFile::Permissions oldPermissions = permissions;
    		permissions &= QFile::ExeGroup;
    		permissions &= QFile::ReadOwner;
    		permissions &= QFile::WriteOwner;
    		permissions &= QFile::ReadUser;
    		permissions &= QFile::WriteUser;
    		permissions &= QFile::ExeUser;
    		permissions &= QFile::ReadGroup;
    		permissions &= QFile::WriteGroup;
    		permissions &= QFile::ReadOther;
    		permissions &= QFile::WriteOther;
    		permissions &= QFile::ExeOther;
    		file.setPermissions(permissions);
    

    What is the correct way of doing this

    Thanks

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      HI
      Are you sure QFile will do it with a folder ?
      Maybe try
      QFile::Permissions perm = QFileInfo( "c:/ACCESS_DENIED/" ).permissions();
      Since it mention folder also.
      Never tried it! so just suggestion.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrahamL
        wrote on last edited by
        #3

        Hi
        Thanks for your reply
        I dont think this will allow me to set the permissions on the folder though

        mrjjM 1 Reply Last reply
        0
        • G GrahamL

          Hi
          Thanks for your reply
          I dont think this will allow me to set the permissions on the folder though

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Yeah, after I posted ,
          I realized that QFileInfo seems to have no setPermissions so
          its back to QFile again. sorry.

          Its under linux I assume ?

          So the user the program runs under/as do have the permission to set permissions ?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            GrahamL
            wrote on last edited by
            #5

            Actually this is running under Windows
            Dont think I can do it using Qt tho

            mrjjM 1 Reply Last reply
            0
            • G GrahamL

              Actually this is running under Windows
              Dont think I can do it using Qt tho

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @GrahamL
              oh
              and you did notice
              extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;

              Well, if you trying to set the Read Only flag for the folder,
              i think you are right that it wont work with Qt and you would have to resort to
              SetFileAttributes
              https://msdn.microsoft.com/en-us/library/aa365535.aspx

              If that is the effect you want to get.

              1 Reply Last reply
              1
              • G Offline
                G Offline
                GrahamL
                wrote on last edited by
                #7

                OK
                Thanks for your help

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved