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. Problem after adding of new key QSetting
Forum Updated to NodeBB v4.3 + New Features

Problem after adding of new key QSetting

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 866 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.
  • M Offline
    M Offline
    moravas
    wrote on last edited by
    #1

    Hy Folks,

    I have a project that uses QSettings instance to store the user custom settings. Recently I have the following .ini file which I manage via a resource file:

    @
    [default]
    client\channelColor\1\color=#55E411
    client\channelColor\2\color=#2D41EA
    client\channelColor\3\color=#FF0000
    client\channelColor\4\color=#F8B80D
    client\channelColor\size=4
    client\channelDecode\1\decode=<NONE>
    client\channelDecode\size=1
    client\channelState\1\state=AC
    client\channelState\2\state=DC
    client\channelState\3\state=GND
    client\channelState\size=3
    general\Connection\connectionCount=4
    general\Connection\serverport=50000
    @

    When my manager class starts, I instantiate a QSettings object (_sessions):
    @
    sessionManager::sessionManager(): _sessions(":/general/res/sessions.ini", QSettings::IniFormat) {
    _session.clear();
    _cache.clear();
    }
    @

    The problem occures when I have to copy the whole group of "[default]" into another. For that I use the following code:
    @
    QMap<QString, QVariant> tmpContainer;
    _sessions.beginGroup("default");
    for(const QString& key: _sessions.allKeys()) {
    tmpContainer[key] = _sessions.value(key);
    }

    _sessions.endGroup();
    _sessions.beginGroup(session);
    for(QMap<QString, QVariant>::iterator it = tmpContainer.begin(); it != tmpContainer.end(); ++it) {
        _sessions.setValue(session + it.key(), it.value());
    }
    
    _sessions.endGroup();
    

    @

    The required behavioral of the above code:

    • set the group to "default"
    • instantiate a QMap that will store the keys and values ofrom the "default" group and fill it up
    • close the group and open another
    • the second cycle write the keys and values into the opened group.

    After the running of the program, I open my .ini file but nothing happened... :(
    Can anybody help me?

    Regards,
    Norbert

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

      Hi,

      Qt resources file are read-only so all your writing to this file will fail.

      You have two solutions there:

      Copy the ini file on the file system somewhere suitable using e.g.e QDesktopServices(Qt 4) or QStandardPaths (Qt 5) with DataLocation and use that one

      Create the file from scratch at application startup (also using a suitable path)

      Hope it helps

      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

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved