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 can we set restriction to .ini file?
Forum Updated to NodeBB v4.3 + New Features

How can we set restriction to .ini file?

Scheduled Pinned Locked Moved General and Desktop
18 Posts 5 Posters 9.3k Views 1 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    I did not want that general user can edit the contents of ini file

    Pratik Agrawal

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      -You must make your key a subkey.-

      EDIT
      Sorry, I completely misread your post. Must have been caused by too less coffee at that time ;-)

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        [quote author="pratik041" date="1322917622"]I did not want that general user can edit the contents of ini file [/quote]

        You could use QFile::setPermissions and set the file attribute to read only. But that would require admin rights. If your user has admin rights, he will be able to change the settings anyhow. So it idoes not make sense. In windows, you may write to the registry, which is less likely to be modified by an unexperienced user.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pratik041
          wrote on last edited by
          #4

          [quote author="koahnig" date="1322933279"][quote author="pratik041" date="1322917622"]I did not want that general user can edit the contents of ini file [/quote]

          You could use QFile::setPermissions and set the file attribute to read only. But that would require admin rights. If your user has admin rights, he will be able to change the settings anyhow. So it idoes not make sense. In windows, you may write to the registry, which is less likely to be modified by an unexperienced user.

          [/quote]

          setPermissions will work only during run time. So when the program is not running does that permissions will persist.

          Pratik Agrawal

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            There is simply no solution.
            The configuration file is a plain text file so it can be edited, modified, moved, deleted, and so on, and the only one that can avoid it is the operating system. If you are running on Unix one (including Apple) you can set an immutable flag to the file, so that nobody except the administrator will be able to alter the file. Something similar can be achieved on linux, but I don't know about windows. However this is not a recommended setup for your application (since you have to do on each installation). It would be better to avoid using a config file and use a binary one (that cannot be easily edited) or an encrypted one.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on last edited by
              #6

              Well you can use simple encryption :)
              Once i use encrypted keys and encrypted fields.;)

              1 Reply Last reply
              0
              • F Offline
                F Offline
                fluca1978
                wrote on last edited by
                #7

                Please note that you could be using the wrong tool for the wrong purpose. Configuration files are what they mean: configurations! You should store there widget layouts, preferences, and other stuff that is not critical for proper application work. Stuff that is critical, such as database password and/or stuff like that should be stored in a private way.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pratik041
                  wrote on last edited by
                  #8

                  [quote author="fluca1978" date="1323071673"]There is simply no solution.
                  The configuration file is a plain text file so it can be edited, modified, moved, deleted, and so on, and the only one that can avoid it is the operating system. If you are running on Unix one (including Apple) you can set an immutable flag to the file, so that nobody except the administrator will be able to alter the file. Something similar can be achieved on linux, but I don't know about windows. However this is not a recommended setup for your application (since you have to do on each installation). It would be better to avoid using a config file and use a binary one (that cannot be easily edited) or an encrypted one. [/quote]

                  For binary file creation which class i should use and how i can read its contents

                  Pratik Agrawal

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    fluca1978
                    wrote on last edited by
                    #9

                    "QDataStream":http://doc.qt.nokia.com/latest/qdatastream.html can help.

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #10

                      [quote author="pratik041" date="1323059347"]
                      setPermissions will work only during run time. So when the program is not running does that permissions will persist.
                      [/quote]

                      There is a static version of setPermissions. So I assume it simply change the file attributes and they should be persistent. However, I have not tried. Nevertheless, in my opinion I would not do it. It is a bit of hazzle. You need to change prior to access and also before program stops.
                      I agree with fluca1978 QSettings is not really meant for your purpose.

                      Is it secrecy or you just do not want the user to mess around?
                      For the latter case you may simply use non-descriptive key names and the values may be output as a string contaning hex values. Nevertheless, I would prefer to use a completely separate file then.

                      Vote the answer(s) that helped you to solve your issue(s)

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pratik041
                        wrote on last edited by
                        #11

                        [quote author="koahnig" date="1323078084"]
                        [quote author="pratik041" date="1323059347"]
                        setPermissions will work only during run time. So when the program is not running does that permissions will persist.
                        [/quote]

                        There is a static version of setPermissions. So I assume it simply change the file attributes and they should be persistent. However, I have not tried. Nevertheless, in my opinion I would not do it. It is a bit of hazzle. You need to change prior to access and also before program stops.
                        I agree with fluca1978 QSettings is not really meant for your purpose.

                        Is it secrecy or you just do not want the user to mess around?
                        For the latter case you may simply use non-descriptive key names and the values may be output as a string contaning hex values. Nevertheless, I would prefer to use a completely separate file then. [/quote]
                        can you say what is the static version of set permission?

                        Pratik Agrawal

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #12

                          Sorry, this becomes to be a bit annoying. You are able to type "setPermission" into Qt Assistant or any other Qt help browser yourself, aren't you? For the time beeing: http://doc.qt.nokia.com/4.7/qfile.html#setPermissions-2

                          Do you intend to write to that file from your application or is it created at build time and should be delivered read-only to your users?

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            pratik041
                            wrote on last edited by
                            #13

                            [quote author="Volker" date="1323089335"]Sorry, this becomes to be a bit annoying. You are able to type "setPermission" into Qt Assistant or any other Qt help browser yourself, aren't you? For the time beeing: http://doc.qt.nokia.com/4.7/qfile.html#setPermissions-2

                            Do you intend to write to that file from your application or is it created at build time and should be delivered read-only to your users?

                            [/quote]
                            It will be delivered read-only to users

                            Pratik Agrawal

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              goetz
                              wrote on last edited by
                              #14

                              In that case I would go with a [[Doc:QResource]]. Either compiled into the binary the usual way or loading/unloading it with registerResource/unregisterResource.

                              If you really want that ini-File, make your installer change the properties of the file to read-only.

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                pratik041
                                wrote on last edited by
                                #15

                                [quote author="Volker" date="1323092949"]In that case I would go with a [[Doc:QResource]]. Either compiled into the binary the usual way or loading/unloading it with registerResource/unregisterResource.

                                If you really want that ini-File, make your installer change the properties of the file to read-only.[/quote]
                                can we store general text information using QResource and it can be compiled into binary.Can you give some example of that?

                                Pratik Agrawal

                                1 Reply Last reply
                                0
                                • F Offline
                                  F Offline
                                  fluca1978
                                  wrote on last edited by
                                  #16

                                  [quote author="pratik041" date="1323146684"]

                                  can we store general text information using QResource and it can be compiled into binary.Can you give some example of that?
                                  [/quote]

                                  Just put the text file into the resource system as you would do for an icon. Then from the application access the file (e.g., using QFile) using the resource path. It does not change your code having the file in the resource system instead of the filesystem, it only changes the path you use to access it.

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    pratik041
                                    wrote on last edited by
                                    #17

                                    [quote author="fluca1978" date="1323154095"]
                                    [quote author="pratik041" date="1323146684"]

                                    can we store general text information using QResource and it can be compiled into binary.Can you give some example of that?
                                    [/quote]

                                    Just put the text file into the resource system as you would do for an icon. Then from the application access the file (e.g., using QFile) using the resource path. It does not change your code having the file in the resource system instead of the filesystem, it only changes the path you use to access it.

                                    [/quote]

                                    Thank you

                                    Pratik Agrawal

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      goetz
                                      wrote on last edited by
                                      #18

                                      [quote author="pratik041" date="1323146684"]
                                      can we store general text information using QResource and it can be compiled into binary.Can you give some example of that?
                                      [/quote]

                                      Qt resources are just a storage container for regular files. You can put into that whatever you want. For examples, see the documentation.

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      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