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. QSettings && insert comment
Forum Updated to NodeBB v4.3 + New Features

QSettings && insert comment

Scheduled Pinned Locked Moved General and Desktop
17 Posts 4 Posters 22.2k 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #6

    [quote author="Giuseppe D’Angelo" date="1292256187"] If you have to create a config file (and let your users modify it), simply don't use QSettings for it but define a file format of your choice.[/quote]

    Thanks,

    I know but this way QSettings do the works of retrive data for me... :-)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cyberbobs
      wrote on last edited by
      #7

      [quote author="peppe" date="1292256187"]If you have to create a config file (and let your users modify it), simply don't use QSettings for it but define a file format of your choice.[/quote]

      Could you please suggest any other text-based configuration format that will be more comfortable for hand-editing by user?

      Okay, most of the modern apps are GUI-configurable and must simply start and work without any hand-configuration by user. But this is not a case for all apps, just for most ;)

      [quote author="Luca" date="1292256437"]I know but this way QSettings do the works of retrive data for me... :-)[/quote]

      Maybe the better solution would be just to install the default commented-by-hands configuration file with your app? Definitely the stupidiest way to solve this problem but it should work :)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #8

        I'm very familiar with some linux configuration files and QSettings config file is similar.
        For example mysql server configuration file is :
        @

        The following options will be passed to all MySQL clients

        [client]
        ...
        ...
        #password = your_password
        port = 3306
        socket = /var/run/mysql/mysql.sock

        Here follows entries for some specific programs

        The MySQL server

        [mysqld]
        port = 3306
        socket = /var/run/mysql/mysql.sock
        ...
        ...
        @

        and as you can see the comments are started with # .

        Using QSettings I can have a similar configuration file without difficult. ;-)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #9

          [quote author="Bobs" date="1292506729"][quote author="peppe" date="1292256187"]If you have to create a config file (and let your users modify it), simply don't use QSettings for it but define a file format of your choice.[/quote]

          Could you please suggest any other text-based configuration format that will be more comfortable for hand-editing by user?

          Okay, most of the modern apps are GUI-configurable and must simply start and work without any hand-configuration by user. But this is not a case for all apps, just for most ;)
          [/quote]

          My point wasn't "INI files have a bad syntax" / "users are not comfortable with them"; I was only pointing out that reading and writing an INI file with QSettings would wipe out all comments, because INI is application-oriented and not human-oriented. That's it :-) If your file is a readonly configuration file, QSettings can save the day! (Although be very careful, since AFAIK there's no way of telling QSettings to never modify the file).

          If you're looking for other formats, well, it really depends on what you're doing, but key/value based files like
          @
          key = value
          @
          are handled easily with QTextStream and QString methods.

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cyberbobs
            wrote on last edited by
            #10

            [quote author="peppe" date="1292511851"]I was only pointing out that reading and writing an INI file with QSettings would wipe out all comments, because INI is application-oriented and not human-oriented. That's it :-)[/quote]
            Okay, sure. But (just as "IMHO") I really don't know any more human-oriented formats than INI for that case :)

            [quote author="peppe" date="1292511851"]If your file is a readonly configuration file, QSettings can save the day! (Although be very careful, since AFAIK there's no way of telling QSettings to never modify the file).[/quote]
            Yep, but I've tried it in a rather big linux only project. It doesn't wipe anything as long, as we're not trying to write any settings to the file :)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luca
              wrote on last edited by
              #11

              I update this post because now with Qt 4.7.1 the sharp comment (#) doesn't works as comment.

              I have a settings file like this:
              @
              [Allarmi]
              22\descrizione=text1
              22\descrizione1=text2
              ;701\descrizione=text3
              ;702\descrizione=text4
              #800\descrizione=text5
              #800\descrizione1=text6
              @

              But # isn't commented out.
              If I do:
              @
              QStringList lista_id_dati_allarmi;
              lista_id_dati_allarmi = setting->childGroups();
              qDebug() << lista_id_dati_allarmi;
              @

              I get:
              @
              ("#800", "22")
              @

              I don't know what's wrong but I remember that with previous Qt version the # comment was recognized as comment.

              Is it possible or am I out of mind...?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stukdev
                wrote on last edited by
                #12

                I remember Qt don't understand the comment if you use write on the qsetting file. I use comment only in a read-only file.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  luca
                  wrote on last edited by
                  #13

                  [quote author="stuk" date="1306854390"]I remember Qt don't understand the comment if you use write on the qsetting file. I use comment only in a read-only file.[/quote]

                  Mine is a read-only file. I edit it by hand.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    stukdev
                    wrote on last edited by
                    #14

                    I try on Qt 4.7.2 now and work well for me.

                    [quote author="Luca" date="1306854471"]
                    [quote author="stuk" date="1306854390"]I remember Qt don't understand the comment if you use write on the qsetting file. I use comment only in a read-only file.[/quote]

                    Mine is a read-only file. I edit it by hand.
                    [/quote]

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      luca
                      wrote on last edited by
                      #15

                      [quote author="stuk" date="1306854962"]I try on Qt 4.7.2 now and work well for me.

                      [/quote]

                      You mean that using sharp (#) in a qsettings file excludes the line ?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        stukdev
                        wrote on last edited by
                        #16

                        Yes, using # work for me on windows.

                        [quote author="Luca" date="1307353306"]
                        [quote author="stuk" date="1306854962"]I try on Qt 4.7.2 now and work well for me.

                        [/quote]

                        You mean that using sharp (#) in a qsettings file excludes the line ?[/quote]

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          luca
                          wrote on last edited by
                          #17

                          [quote author="stuk" date="1307362137"]Yes, using # work for me on windows.

                          [/quote]

                          Ok, thanks.
                          Unfortunately it doesn't works in Linux... it seems...

                          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