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] Reading QColor from an INI file
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Reading QColor from an INI file

Scheduled Pinned Locked Moved General and Desktop
25 Posts 3 Posters 16.0k 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.
  • A Offline
    A Offline
    astodolski
    wrote on last edited by
    #1

    I have an entry in an INI file that is supposed to set a QColor.

    When I execute the following line:

    @
    m_MarkerColor = IniSettings.value("Testing/MarkerColor", QColor(128, 0, 0)).value<QColor>();
    @

    m_MarkerColor is an Invalid color. The entry in the INI file is:

    @
    [Testing]
    MarkerColor=@QColor(0 0 128)
    @

    I suspect that perhaps the format may be incorrect as listed in the INI file or is it how I call the value function.

    Thanks in advance

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Subst27
      wrote on last edited by
      #2

      Hello!

      for example

      QColor m_MarkerColor;
      QSettings settings;

      write:

      settings.setValue("MarkerColor",m_MarkerColor.rgba());

      read:

      m_MarkerColor=settings.value("MarkerColor",0).toUInt();

      1 Reply Last reply
      0
      • A Offline
        A Offline
        astodolski
        wrote on last edited by
        #3

        Returns 0 (the default). How do you format the INI file for the correct value to be read? I'm only concerned with reading and not setting.

        Thanks

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Subst27
          wrote on last edited by
          #4

          look rgba format of the color conseption

          place in your ini such record (just sample)

          MarkerColor=4294967040

          it's look like 4294967040, for example

          also u can use the #FFFFFFFF expression, but remember that it is 16 number base and u must interpret it in program

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Subst27
            wrote on last edited by
            #5

            in Assistant

            An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              astodolski
              wrote on last edited by
              #6

              I understand. I was wanting to set it as a QColor entry in the INI file. I wonder if that is even possible

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Subst27
                wrote on last edited by
                #7

                why?

                really possible.

                you can read value as string and then analyze it whith RegExp

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  astodolski
                  wrote on last edited by
                  #8

                  [quote author="Subst27" date="1421077722"]in Assistant

                  An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
                  [/quote]

                  So the entry in the INI file then would be:

                  @
                  MarkerColor= @QRgb(#00000080)
                  @

                  OR

                  @
                  MarkerColor= #00000080
                  @

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    astodolski
                    wrote on last edited by
                    #9

                    [quote author="Subst27" date="1421077722"]in Assistant

                    An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
                    [/quote]

                    So the entry in the INI file then would be:

                    @
                    MarkerColor= @QRgb(#00000080)
                    @

                    OR

                    @
                    MarkerColor= #00000080
                    @

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      astodolski
                      wrote on last edited by
                      #10

                      [quote author="Subst27" date="1421077934"]why?

                      really possible.

                      you can read value as string and then analyze it whith RegExp

                      [/quote]

                      As string? Didn't consider that. OK. I'll try that

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Subst27
                        wrote on last edited by
                        #11

                        MarkerColor= #00000080

                        It seems the obvious and the apply the toHex()

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          Subst27
                          wrote on last edited by
                          #12

                          whith the string like QColor(R,G,B)

                          you can remove QColor and brackets and then whis split(",") take the Red,Green and Blue values of your color

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            astodolski
                            wrote on last edited by
                            #13

                            [quote author="Subst27" date="1421078199"]MarkerColor= #00000080

                            It seems the obvious and the apply the toHex()[/quote]

                            toHex() isn't available in this context.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Subst27
                              wrote on last edited by
                              #14

                              try to remove # sign

                              it's issuer of syntax

                              from Assistant

                              QByteArray QByteArray::​toHex() const

                              Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                astodolski
                                wrote on last edited by
                                #15

                                [quote author="Subst27" date="1421078846"]try to remove # sign

                                it's issuer of syntax

                                from Assistant

                                QByteArray QByteArray::​toHex() const

                                Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.
                                [/quote]

                                It is unclear what you are trying to illustrate.

                                Perhaps a trivial example?

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  Subst27
                                  wrote on last edited by
                                  #16

                                  can you wait some minutes?

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    astodolski
                                    wrote on last edited by
                                    #17

                                    [quote author="Subst27" date="1421079781"]can you wait some minutes?[/quote]

                                    Of course

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      Subst27
                                      wrote on last edited by
                                      #18

                                      I found better variant

                                      in INI

                                      [common]
                                      color=#FF0000

                                      result

                                      "#FF0000"
                                      16711680
                                      QColor(ARGB 1, 1, 0, 0)

                                      look code in next message

                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        Subst27
                                        wrote on last edited by
                                        #19

                                        @QSettings settings(qApp->applicationDirPath()+"/color.ini",QSettings::IniFormat);

                                        QColor color;
                                        settings.beginGroup("common");
                                        QString string=settings.value("color","#0000FF").toString();
                                        qDebug()<<string;
                                        string.remove(0,1);
                                        bool ok;
                                        uint value=string.toUInt(&ok,16);
                                        qDebug()<<value;
                                        color=QColor::fromRgb(value);
                                        qDebug()<<color;@

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          andre
                                          wrote on last edited by
                                          #20

                                          I'd add a bit more checking of the input. Before removing the first character, check if it actually is a # sign. And check if the length of the rest is what you expect (6 characters for a 3x8bit color).

                                          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