Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Reading QColor from an INI file
Qt 6.12 LTS 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 23.7k 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.
  • 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
            • S Offline
              S Offline
              Subst27
              wrote on last edited by
              #21

              [quote author="Andre" date="1421081171"]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).[/quote]

              well.
              I've just wrote the principal solve

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

                [quote author="Andre" date="1421081171"]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).[/quote]

                Thanks as always @Andre and especially thanks to @Subst27! I will mark this Solved for now but will need to refine it a bit

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

                  [quote author="Subst27" date="1421081450"]
                  [quote author="Andre" date="1421081171"]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).[/quote]

                  well.
                  I've just wrote the principal solve[/quote]

                  Yes, of course. But reading an ini file is essentially user imput, so I think input checking should not be just an afterthought. That's why I mentioned it.

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

                    sure u are right

                    for this purpose global better to define T QVariant::​value() const for QColor
                    :)
                    and problem die away. :)

                    Well! I see you

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

                      I just wanted to add what I think is a better solution - at least for me. The issue was centered around the proper forming of the key in the input file which if not done correctly yielded a Invalid color status for the QColor. I went back to reading the value in as a number - not a string.

                      @
                      [Testing]
                      MarkerColor=#800000
                      @

                      and in code:
                      @
                      m_MarkerColor = IniSettings.value("Testing/MarkerColor").value<QColor>();
                      @

                      Sincere thanks to all who have assisted and contributed.

                      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
                      • Unsolved