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] Problem with QSetting
Forum Updated to NodeBB v4.3 + New Features

[Solved] Problem with QSetting

Scheduled Pinned Locked Moved General and Desktop
18 Posts 4 Posters 5.3k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #5

    this is my ini file content :

    [General]
    Server=192.168.1.1

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on last edited by
      #6

      did you check the typo in

      QString address = obSettings.value(" Serever ","").toString();

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #7

        Yes I have a mistake in mytype server ... serever no server.

        but does not work again :(

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #8

          This is my code see again please :

          @
          QSettings obSettings("database.ini", QSettings::IniFormat);
          obSettings.beginGroup("General");
          QString server = obSettings.value("Server", "").toString();
          obSettings.endGroup();

          qDebug() << "Server = " << server;
          @

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #9

            Where is database.ini located ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #10

              [quote author="SGaist" date="1398287969"]Where is database.ini located ?[/quote]

              No specific path !

              I can write into this ini file with below code :

              QSettings settings("database.ini", QSettings::IniFormat);
              settings.setValue("Server", "192.168.1.1");

              but for read.... I don't know why doesn't work.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #11

                Just a wild idea:

                try with foo in place of General for the group name

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #12

                  [quote author="SGaist" date="1398288372"]Just a wild idea:

                  try with foo in place of General for the group name [/quote]

                  Can you show me with example ? :)

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    Before that, just saw something:

                    @
                    QSettings settings(“database.ini”, QSettings::IniFormat); settings.setValue(“Server”, “192.168.1.1”);
                    @

                    You don't begin the group, is that a missing line ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #14

                      [quote author="SGaist" date="1398289288"]Before that, just saw something:

                      @
                      QSettings settings(“database.ini”, QSettings::IniFormat); settings.setValue(“Server”, “192.168.1.1”);
                      @

                      You don't begin the group, is that a missing line ?[/quote]

                      but this is not for Read from ini file ! I don't have problem with setValue :)
                      My main problem is reading from file :(

                      You just show me how can I read from ini file , maybe I have a little mistake.
                      Of course my ini file content is :

                      [General]
                      Server=192.168.1.1

                      Why I can't read 192.168.1.1 from server!?

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #15

                        The thing is: your writing to the init file and your reading must match.
                        Using :

                        @
                        QSettings settings(“database.ini”, QSettings::IniFormat); settings.setValue(“Server”, “192.168.1.1”);
                        @

                        to write, then you must use

                        @
                        QSettings settings(“database.ini”, QSettings::IniFormat);
                        QString server = settings.value(“Server”, “”).toString();
                        @

                        to read it back

                        [edit: corrected my code]

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #16

                          No ! error... in QString server = settings.value(“Server”, “”);

                          I changed it to below format with QVariant

                          @
                          QSettings settings("database.ini", QSettings::IniFormat);
                          QVariant server = settings.value("Server", "");

                          qDebug() << "Server = " << server.toString();
                          @

                          Result is :

                          Server = "192.168.1.1"

                          Good work :)
                          Thank you very much. ;)

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #17

                            You're welcome !

                            Since you have your settings working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • ? Offline
                              ? Offline
                              A Former User
                              wrote on last edited by
                              #18

                              Yes of course !
                              title is changed :)

                              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