Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED]How to write values in a existing .ini file

    General and Desktop
    5
    7
    5298
    Loading More Posts
    • 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.
    • R
      roach03 last edited by

      Hi,

         I have a Line Edit widget in my form and I want to pass the values on a existing .ini file via pushbutton widget. could this be possible? can you give me a sample code for this? TIA
      
      1 Reply Last reply Reply Quote 0
      • K
        koahnig last edited by

        From the "documentation":http://qt-project.org/doc/qt-5/QSettings.html
        [quote]QSettings stores settings. Each setting consists of a QString that specifies the setting's name (the key) and a QVariant that stores the data associated with the key. To write a setting, use setValue(). For example:
        [/quote]
        Description for "setValue":http://qt-project.org/doc/qt-5/qsettings.html#setValue

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

        1 Reply Last reply Reply Quote 0
        • A
          arsinte_andrei last edited by

          @void Tools_Settings::on_buttonOk_clicked(){
          QSettings mySettings = new QSettings("existingIniFile.ini", QSettings::IniFormat);
          mySettings->setValue("MainGroup/SubGroup", ui->editMyLineEdit->text());
          }@
          hope this will help you
          If this will solve your problem kingdly edit the titple of the main post with
          [SOLVED]

          1 Reply Last reply Reply Quote 0
          • A
            AbdelAli last edited by

            Hello, is there another way to R/W in INI files rather than QSetting ?
            thnx

            1 Reply Last reply Reply Quote 0
            • M
              MuldeR last edited by

              [quote author="AbdelAli" date="1406102515"]Hello, is there another way to R/W in INI files rather than QSetting ?
              thnx[/quote]

              INI is a very simple text format. In the easiest case, you can simply use QFile + QTextStream and read the file line by line. Or you can use QFile to append additional lines to the INI file. It becomes slightly more complex though, if you actually need to insert lines or modify existing INI file entries...

              Yet another way of accessing INI files is using the WritePrivateProfileString and GetPrivateProfileString functions. But those are Windows only.

              My OpenSource software at: http://muldersoft.com/

              Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

              Go visit the coop: http://youtu.be/Jay...

              1 Reply Last reply Reply Quote 0
              • R
                roach03 last edited by

                Thanks for the inputs unfortunately I haven't tried this because the project that requires this, changed it's specs. But good to know though

                1 Reply Last reply Reply Quote 0
                • A
                  AbdelAli last edited by

                  Thank you MuldR, I finished by using QSettings, it's the simplest way to do it,

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post