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 read INI file
QtWS25 Last Chance

How to read INI file

Scheduled Pinned Locked Moved Unsolved General and Desktop
iniqt5.15.2
10 Posts 4 Posters 1.2k Views
  • 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.
  • D Offline
    D Offline
    DimaSsS
    wrote on 11 Oct 2023, 07:24 last edited by DimaSsS 10 Nov 2023, 07:25
    #1

    Is it possible to read ini file with duplicates keys using QSettings?
    [secret]
    shard=/app/key/shard0.pem
    shard=/app/key/shard1.pem
    shard=/app/key/shard2.pem
    shard=/app/key/shard3.pem
    shard=/app/key/shard4.pem

    I can not change ini file because it's part of another program.

    J J 2 Replies Last reply 11 Oct 2023, 07:30
    0
    • D DimaSsS
      11 Oct 2023, 07:24

      Is it possible to read ini file with duplicates keys using QSettings?
      [secret]
      shard=/app/key/shard0.pem
      shard=/app/key/shard1.pem
      shard=/app/key/shard2.pem
      shard=/app/key/shard3.pem
      shard=/app/key/shard4.pem

      I can not change ini file because it's part of another program.

      J Offline
      J Offline
      JonB
      wrote on 11 Oct 2023, 07:30 last edited by
      #2

      @DimaSsS
      Have you tried it?
      My guess would be that the last line overrides the earlier ones, you end up with shard having value /app/key/shard4.pem?

      D 1 Reply Last reply 11 Oct 2023, 07:39
      1
      • J JonB
        11 Oct 2023, 07:30

        @DimaSsS
        Have you tried it?
        My guess would be that the last line overrides the earlier ones, you end up with shard having value /app/key/shard4.pem?

        D Offline
        D Offline
        DimaSsS
        wrote on 11 Oct 2023, 07:39 last edited by DimaSsS 10 Nov 2023, 07:41
        #3

        @JonB Yes
        i tried to use allKeys() and childKKeys() and its returns me only shard=/app/key/shard4.pem
        but i need all shards and save them into QStringList:(

        J 2 Replies Last reply 11 Oct 2023, 07:41
        0
        • D DimaSsS
          11 Oct 2023, 07:39

          @JonB Yes
          i tried to use allKeys() and childKKeys() and its returns me only shard=/app/key/shard4.pem
          but i need all shards and save them into QStringList:(

          J Offline
          J Offline
          JonB
          wrote on 11 Oct 2023, 07:41 last edited by JonB 10 Nov 2023, 07:42
          #4

          @DimaSsS
          Which is just what I suspected might be the result!
          You may have to read that file yourself to get the behaviour you want, as either both/of: .ini files don't work like that and/or Qt's reading code does not offer you that.

          1 Reply Last reply
          0
          • D DimaSsS
            11 Oct 2023, 07:24

            Is it possible to read ini file with duplicates keys using QSettings?
            [secret]
            shard=/app/key/shard0.pem
            shard=/app/key/shard1.pem
            shard=/app/key/shard2.pem
            shard=/app/key/shard3.pem
            shard=/app/key/shard4.pem

            I can not change ini file because it's part of another program.

            J Online
            J Online
            J.Hilk
            Moderators
            wrote on 11 Oct 2023, 07:43 last edited by
            #5

            @DimaSsS QSettings isn't meant to do that. If you assign multiple values to the same key, the entry is overwritten.

            From QSettings point of view your ini file is faulty and it just happens to work out, that one entry is read anyway.

            You will have to parse that file yourself


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1
            • D DimaSsS
              11 Oct 2023, 07:39

              @JonB Yes
              i tried to use allKeys() and childKKeys() and its returns me only shard=/app/key/shard4.pem
              but i need all shards and save them into QStringList:(

              J Offline
              J Offline
              JonB
              wrote on 11 Oct 2023, 07:47 last edited by
              #6

              @DimaSsS
              If you do go down the route of parsing that file yourself, it looks like you could use QSettings::Format QSettings::registerFormat() supplying your own QSettings::ReadFunc so as to end up successfully interoperating with QSettings if you want that.

              1 Reply Last reply
              1
              • K Offline
                K Offline
                Ketan__Patel__0011
                wrote on 24 Nov 2023, 06:27 last edited by
                #7

                You should see the following video about QSettings class and how to read config file like .INI File in Qt Application

                Read And Write in INI File : https://www.youtube.com/watch?v=62Mzbt8QqLE

                Read And Write in Registry : https://www.youtube.com/watch?v=1v_oDXDhKgg

                J 1 Reply Last reply 24 Nov 2023, 08:42
                0
                • K Ketan__Patel__0011
                  24 Nov 2023, 06:27

                  You should see the following video about QSettings class and how to read config file like .INI File in Qt Application

                  Read And Write in INI File : https://www.youtube.com/watch?v=62Mzbt8QqLE

                  Read And Write in Registry : https://www.youtube.com/watch?v=1v_oDXDhKgg

                  J Offline
                  J Offline
                  JonB
                  wrote on 24 Nov 2023, 08:42 last edited by
                  #8

                  @Ketan__Patel__0011
                  This is general video about using QSettings. It has nothing to say about the OP's question of handling duplicate keys.

                  K 1 Reply Last reply 24 Nov 2023, 12:00
                  1
                  • J JonB
                    24 Nov 2023, 08:42

                    @Ketan__Patel__0011
                    This is general video about using QSettings. It has nothing to say about the OP's question of handling duplicate keys.

                    K Offline
                    K Offline
                    Ketan__Patel__0011
                    wrote on 24 Nov 2023, 12:00 last edited by
                    #9

                    @JonB
                    Actually i Did not read the whole thread.
                    i just read the Title of thread and share something according it.

                    J 1 Reply Last reply 24 Nov 2023, 13:11
                    0
                    • K Ketan__Patel__0011
                      24 Nov 2023, 12:00

                      @JonB
                      Actually i Did not read the whole thread.
                      i just read the Title of thread and share something according it.

                      J Offline
                      J Offline
                      JonB
                      wrote on 24 Nov 2023, 13:11 last edited by
                      #10

                      @Ketan__Patel__0011
                      :) OK. This thread is asking about a particular problem, "duplicate keys", which I don't think QSettings will handle as the OP wishes.

                      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