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. [SOLVED]How to write values in a existing .ini file
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 6.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.
  • R Offline
    R Offline
    roach03
    wrote on last edited by
    #1

    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
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        arsinte_andrei
        wrote on last edited by
        #3

        @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
        0
        • A Offline
          A Offline
          AbdelAli
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #5

            [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
            0
            • R Offline
              R Offline
              roach03
              wrote on last edited by
              #6

              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
              0
              • A Offline
                A Offline
                AbdelAli
                wrote on last edited by
                #7

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

                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