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. ini parsing does not return value

ini parsing does not return value

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 698 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.
  • N Offline
    N Offline
    Noatqt
    wrote on last edited by
    #1

    Hi,
    The following is a part of my code:

    QSettings iniSetting(_myIni,QSettings::IniFormat);
    iniSetting.setIniCodec("UTF8");
    iniSetting.beginGroup("run");
    _runTimeString = iniSetting.value("run_time").toString();
    

    As long as the ini value of run_time is less than a day (e.g. 11:23:45) _runTimeString is as expected.
    But when the value in the ini file is " 1 day, 0:08:44" - I get an empty string.

    Why is this happening and how can I fix it?
    Thanks!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      So what's the actual value of 'run_time' in your ini file?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      N 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        So what's the actual value of 'run_time' in your ini file?

        N Offline
        N Offline
        Noatqt
        wrote on last edited by
        #3

        @Christian-Ehrlicher

        This is the line in the ini that is not parsed correctly:
        run_time = 1 day, 0:08:44

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Noatqt said in ini parsing does not return value:

          1 day, 0:08:44

          This is no correct format for a QString. I would guess it's

          run_time = "1 day, 0:08:44"
          

          But to know it for sure try to write it our with QSettings into your ini file.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          N 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @Noatqt said in ini parsing does not return value:

            1 day, 0:08:44

            This is no correct format for a QString. I would guess it's

            run_time = "1 day, 0:08:44"
            

            But to know it for sure try to write it our with QSettings into your ini file.

            N Offline
            N Offline
            Noatqt
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            The ini file was created by a python script. all values in it are strings. The Qt application is reading an existing file.
            Why is this line different from the line that is parsed correctly?

            correct parsing:
            run_time = 0:08:44

            incorrect parsing:
            run_time = 1 day, 0:08:44

            JonBJ 1 Reply Last reply
            0
            • N Noatqt

              @Christian-Ehrlicher

              The ini file was created by a python script. all values in it are strings. The Qt application is reading an existing file.
              Why is this line different from the line that is parsed correctly?

              correct parsing:
              run_time = 0:08:44

              incorrect parsing:
              run_time = 1 day, 0:08:44

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Noatqt
              Is the problem to do with having a (non-quoted) space in the value in the file?

              Qt does not guarantee to read in an arbitrary .ini file produced by some other code. I don't know whether that is the case here.

              @Christian-Ehrlicher suggested you test what QSettings produces when saving that string.

              N 1 Reply Last reply
              2
              • JonBJ JonB

                @Noatqt
                Is the problem to do with having a (non-quoted) space in the value in the file?

                Qt does not guarantee to read in an arbitrary .ini file produced by some other code. I don't know whether that is the case here.

                @Christian-Ehrlicher suggested you test what QSettings produces when saving that string.

                N Offline
                N Offline
                Noatqt
                wrote on last edited by
                #7

                @JonB

                Yes! that was it! Thanks
                is there a way (other than editing the ini) to have Qt read values containing spaces?

                Christian EhrlicherC 1 Reply Last reply
                0
                • N Noatqt

                  @JonB

                  Yes! that was it! Thanks
                  is there a way (other than editing the ini) to have Qt read values containing spaces?

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Noatqt said in ini parsing does not return value:

                  to have Qt read values containing spaces?

                  QStringList is maybe worth a try.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  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