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 i parser the .ini file?
Forum Updated to NodeBB v4.3 + New Features

how can i parser the .ini file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 4 Posters 15.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.
  • V victor wang

    @Flotisable
    Actually i need it to help me get the group automatically.
    I know Qt can do it but i do not know how to do it.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @victor-wang What about QSettings? http://doc.qt.io/qt-5/qsettings.html

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    2
    • V victor wang

      @Flotisable
      Actually i need it to help me get the group automatically.
      I know Qt can do it but i do not know how to do it.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #5

      @victor-wang Use http://doc.qt.io/qt-5/qsettings.html#QSettings-2 and pass QSettings::IniFormat as first parameter.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply
      4
      • jsulmJ jsulm

        @victor-wang Use http://doc.qt.io/qt-5/qsettings.html#QSettings-2 and pass QSettings::IniFormat as first parameter.

        V Offline
        V Offline
        victor wang
        wrote on last edited by
        #6

        @jsulm
        Do you have any example for me?
        It is too abstract for me to read.

        jsulmJ 1 Reply Last reply
        0
        • V victor wang

          @jsulm
          Do you have any example for me?
          It is too abstract for me to read.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #7

          @victor-wang Please read documentation (http://doc.qt.io/qt-5/qsettings.html) there are examples:

             QCoreApplication::setOrganizationName("MySoft");
              QCoreApplication::setOrganizationDomain("mysoft.com");
              QCoreApplication::setApplicationName("Star Runner");
              ...
              QSettings settings;
              int margin = settings.value("editor/wrapMargin").toInt();
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          V 1 Reply Last reply
          3
          • jsulmJ jsulm

            @victor-wang Please read documentation (http://doc.qt.io/qt-5/qsettings.html) there are examples:

               QCoreApplication::setOrganizationName("MySoft");
                QCoreApplication::setOrganizationDomain("mysoft.com");
                QCoreApplication::setApplicationName("Star Runner");
                ...
                QSettings settings;
                int margin = settings.value("editor/wrapMargin").toInt();
            
            V Offline
            V Offline
            victor wang
            wrote on last edited by
            #8

            @jsulm
            For example, i have an .ini file called poduct.ini.
            So if i want to set this one how can i possible set?

            What is the meaning of organization name,organization Domain and application name stand for?

            jsulmJ 1 Reply Last reply
            0
            • V victor wang

              @jsulm
              For example, i have an .ini file called poduct.ini.
              So if i want to set this one how can i possible set?

              What is the meaning of organization name,organization Domain and application name stand for?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @victor-wang Please read documentation, there is a reason why Qt provides documentation: http://doc.qt.io/qt-5/qsettings.html#QSettings-3
              You can ignore Organization/Domain/ApplicationName in your case.

              QSettings settings("my_ini_file.ini", QSettings::IniFormat);
              

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              V 2 Replies Last reply
              1
              • jsulmJ jsulm

                @victor-wang Please read documentation, there is a reason why Qt provides documentation: http://doc.qt.io/qt-5/qsettings.html#QSettings-3
                You can ignore Organization/Domain/ApplicationName in your case.

                QSettings settings("my_ini_file.ini", QSettings::IniFormat);
                
                V Offline
                V Offline
                victor wang
                wrote on last edited by
                #10

                @jsulm
                I have saw this but that let me doubt how can it know where my file is put?
                My file can be located at anywhere but why can this function find the directly?

                jsulmJ J.HilkJ 2 Replies Last reply
                0
                • V victor wang

                  @jsulm
                  I have saw this but that let me doubt how can it know where my file is put?
                  My file can be located at anywhere but why can this function find the directly?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  @victor-wang Since it is your file you have to know where it is and pass the whole path:

                  QSettings settings("/PATH_TO_MY_INI_FILE/my_ini_file.ini", QSettings::IniFormat);
                  

                  As alternative you can let Qt handle this if you pass Organization/Domain/ApplicationName. Again: read documentation.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • V victor wang

                    @jsulm
                    I have saw this but that let me doubt how can it know where my file is put?
                    My file can be located at anywhere but why can this function find the directly?

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #12

                    @victor-wang

                    if the ini-file is not in the default path, you have to modify "my_ini_file.ini" in such a way that it describes the path of the file.
                    This is the case for all file related operations fyi.

                    QSettings settings("c:/Folder1/Folder2/..../my_ini_file.ini", QSettings::IniFormat);


                    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.

                    V 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @victor-wang Please read documentation, there is a reason why Qt provides documentation: http://doc.qt.io/qt-5/qsettings.html#QSettings-3
                      You can ignore Organization/Domain/ApplicationName in your case.

                      QSettings settings("my_ini_file.ini", QSettings::IniFormat);
                      
                      V Offline
                      V Offline
                      victor wang
                      wrote on last edited by
                      #13
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • J.HilkJ J.Hilk

                        @victor-wang

                        if the ini-file is not in the default path, you have to modify "my_ini_file.ini" in such a way that it describes the path of the file.
                        This is the case for all file related operations fyi.

                        QSettings settings("c:/Folder1/Folder2/..../my_ini_file.ini", QSettings::IniFormat);

                        V Offline
                        V Offline
                        victor wang
                        wrote on last edited by victor wang
                        #14

                        @J.Hilk
                        Are these path be the meaning of your default path?

                        $HOME/.config/MySoft/Star Runner.ini (Qt for Embedded Linux: $HOME/Settings/MySoft/Star Runner.ini)
                        $HOME/.config/MySoft.ini (Qt for Embedded Linux: $HOME/Settings/MySoft.ini)
                        /etc/xdg/MySoft/Star Runner.ini
                        /etc/xdg/MySoft.ini
                        
                        J.HilkJ 1 Reply Last reply
                        0
                        • V victor wang

                          @J.Hilk
                          Are these path be the meaning of your default path?

                          $HOME/.config/MySoft/Star Runner.ini (Qt for Embedded Linux: $HOME/Settings/MySoft/Star Runner.ini)
                          $HOME/.config/MySoft.ini (Qt for Embedded Linux: $HOME/Settings/MySoft.ini)
                          /etc/xdg/MySoft/Star Runner.ini
                          /etc/xdg/MySoft.ini
                          
                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by J.Hilk
                          #15

                          @victor-wang

                          Quote from the docu:

                          Platform-Specific Notes

                          Locations Where Application Settings Are Stored

                          As mentioned in the Fallback Mechanism section, QSettings stores settings for an application in up to four locations, depending on whether the settings are user-specific or system-wide and whether the settings are application-specific or organization-wide. For simplicity, we're assuming the organization is called MySoft and the application is called Star Runner.

                          On Unix systems, if the file format is NativeFormat, the following files are used by default:

                          $HOME/.config/MySoft/Star Runner.conf (Qt for Embedded Linux: $HOME/Settings/MySoft/Star Runner.conf)
                          $HOME/.config/MySoft.conf (Qt for Embedded Linux: $HOME/Settings/MySoft.conf)
                          /etc/xdg/MySoft/Star Runner.conf
                          /etc/xdg/MySoft.conf

                          The answer therefore is yes


                          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.

                          V 2 Replies Last reply
                          0
                          • J.HilkJ J.Hilk

                            @victor-wang

                            Quote from the docu:

                            Platform-Specific Notes

                            Locations Where Application Settings Are Stored

                            As mentioned in the Fallback Mechanism section, QSettings stores settings for an application in up to four locations, depending on whether the settings are user-specific or system-wide and whether the settings are application-specific or organization-wide. For simplicity, we're assuming the organization is called MySoft and the application is called Star Runner.

                            On Unix systems, if the file format is NativeFormat, the following files are used by default:

                            $HOME/.config/MySoft/Star Runner.conf (Qt for Embedded Linux: $HOME/Settings/MySoft/Star Runner.conf)
                            $HOME/.config/MySoft.conf (Qt for Embedded Linux: $HOME/Settings/MySoft.conf)
                            /etc/xdg/MySoft/Star Runner.conf
                            /etc/xdg/MySoft.conf

                            The answer therefore is yes

                            V Offline
                            V Offline
                            victor wang
                            wrote on last edited by
                            #16

                            @J.Hilk
                            So if my INI file is not at the default path i should move it in to the right path?
                            Can't i give the direct path if i am not in the default path?

                            jsulmJ 1 Reply Last reply
                            0
                            • V victor wang

                              @J.Hilk
                              So if my INI file is not at the default path i should move it in to the right path?
                              Can't i give the direct path if i am not in the default path?

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #17

                              @victor-wang "Can't i give the direct path if i am not in the default path?" - isn't it what I provided before?
                              So here it is again:

                              QSettings settings("/PATH_TO_MY_INI_FILE/my_ini_file.ini", QSettings::IniFormat);
                              

                              Just provide the complete path to the file, that's all.

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • J.HilkJ J.Hilk

                                @victor-wang

                                Quote from the docu:

                                Platform-Specific Notes

                                Locations Where Application Settings Are Stored

                                As mentioned in the Fallback Mechanism section, QSettings stores settings for an application in up to four locations, depending on whether the settings are user-specific or system-wide and whether the settings are application-specific or organization-wide. For simplicity, we're assuming the organization is called MySoft and the application is called Star Runner.

                                On Unix systems, if the file format is NativeFormat, the following files are used by default:

                                $HOME/.config/MySoft/Star Runner.conf (Qt for Embedded Linux: $HOME/Settings/MySoft/Star Runner.conf)
                                $HOME/.config/MySoft.conf (Qt for Embedded Linux: $HOME/Settings/MySoft.conf)
                                /etc/xdg/MySoft/Star Runner.conf
                                /etc/xdg/MySoft.conf

                                The answer therefore is yes

                                V Offline
                                V Offline
                                victor wang
                                wrote on last edited by
                                #18

                                @J.Hilk
                                http://doc.qt.io/qt-5/qsettings.html#setPath

                                I think i can set the path myself by UserScope.
                                But It has to be under /home.

                                J.HilkJ 1 Reply Last reply
                                0
                                • V victor wang

                                  @J.Hilk
                                  http://doc.qt.io/qt-5/qsettings.html#setPath

                                  I think i can set the path myself by UserScope.
                                  But It has to be under /home.

                                  J.HilkJ Offline
                                  J.HilkJ Offline
                                  J.Hilk
                                  Moderators
                                  wrote on last edited by
                                  #19

                                  @victor-wang

                                  Either you have a hard time understanding what answeres are give to you, or you're messing with us ;-)

                                  So if my INI file is not at the default path i should move it in to the right path?

                                  That's a definite maybe.

                                  Can't i give the direct path if i am not in the default path?

                                  Yes:

                                  @J.Hilk said in [how can i parser the .ini file?](/topic/77013/how-can-i-parser-the-ini-

                                  QSettings settings("c:/Folder1/Folder2/..../my_ini_file.ini", QSettings::IniFormat);

                                  and

                                  @jsulm said in how can i parser the .ini file?:

                                  QSettings settings("/PATH_TO_MY_INI_FILE/my_ini_file.ini", QSettings::IniFormat);
                                  

                                  Just provide the complete path to the file, that's all.


                                  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.

                                  V 1 Reply Last reply
                                  1
                                  • J.HilkJ J.Hilk

                                    @victor-wang

                                    Either you have a hard time understanding what answeres are give to you, or you're messing with us ;-)

                                    So if my INI file is not at the default path i should move it in to the right path?

                                    That's a definite maybe.

                                    Can't i give the direct path if i am not in the default path?

                                    Yes:

                                    @J.Hilk said in [how can i parser the .ini file?](/topic/77013/how-can-i-parser-the-ini-

                                    QSettings settings("c:/Folder1/Folder2/..../my_ini_file.ini", QSettings::IniFormat);

                                    and

                                    @jsulm said in how can i parser the .ini file?:

                                    QSettings settings("/PATH_TO_MY_INI_FILE/my_ini_file.ini", QSettings::IniFormat);
                                    

                                    Just provide the complete path to the file, that's all.

                                    V Offline
                                    V Offline
                                    victor wang
                                    wrote on last edited by
                                    #20

                                    @J.Hilk
                                    This is my code here
                                    And i got some error.
                                    Is there anything i need to fix?

                                    This is an error here

                                    Please help!

                                    FlotisableF 1 Reply Last reply
                                    0
                                    • V victor wang

                                      @J.Hilk
                                      This is my code here
                                      And i got some error.
                                      Is there anything i need to fix?

                                      This is an error here

                                      Please help!

                                      FlotisableF Offline
                                      FlotisableF Offline
                                      Flotisable
                                      wrote on last edited by
                                      #21

                                      @victor-wang
                                      the ; should not at the end of foreach statement, or it will do nothing and finish the foreach statement, just like for statement.

                                      you should write qDebug() not qDebug, you forget the parentheses.

                                      V 1 Reply Last reply
                                      0
                                      • FlotisableF Flotisable

                                        @victor-wang
                                        the ; should not at the end of foreach statement, or it will do nothing and finish the foreach statement, just like for statement.

                                        you should write qDebug() not qDebug, you forget the parentheses.

                                        V Offline
                                        V Offline
                                        victor wang
                                        wrote on last edited by
                                        #22

                                        @Flotisable
                                        Sorry, i got this :)

                                        Besides, i got a question.
                                        Can i only read the key which the value is true?

                                        FlotisableF 1 Reply Last reply
                                        0
                                        • V victor wang

                                          @Flotisable
                                          Sorry, i got this :)

                                          Besides, i got a question.
                                          Can i only read the key which the value is true?

                                          FlotisableF Offline
                                          FlotisableF Offline
                                          Flotisable
                                          wrote on last edited by
                                          #23

                                          @victor-wang
                                          I think you have to write some code to test it, just read the key if it pass the test.

                                          V 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