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. Trouble with .ini settings file
Forum Updated to NodeBB v4.3 + New Features

Trouble with .ini settings file

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 218 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.
  • UnitScanU Offline
    UnitScanU Offline
    UnitScan
    wrote on last edited by UnitScan
    #1

    I have ab .ini file structured like this:

    [theme]
    background=#000000
    text=#87ca00
    border=#87ca00
    slider=#ffff7f

    I need to retrieve the value of each key. This is my attempt

        settings = new QSettings(QDir::currentPath() + "/config.ini", QSettings::IniFormat);
        settings->beginGroup("theme");
        QStringList keys = settings->childKeys();
        for (int i=0; i < keys.size(); i++) {
            QString value = "theme/";
            value.append(keys.at(i));
            qDebug() << "key" << keys.at(i) << settings->value(value).toString();
        }
        settings->endGroup();
    

    The output is

    key "background" ""
    key "border" ""
    key "slider" ""
    key "text" ""

    As you can see, the text corresponding to the key value is empty.
    Where am I doing wrong?

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

      @UnitScan said in Trouble with .ini settings file:

      QString value = "theme/";

      You already called beginGroup() within this.

      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
      2
      • UnitScanU Offline
        UnitScanU Offline
        UnitScan
        wrote on last edited by
        #3

        Very well, thank you!

        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