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 with my WriteFunc for QSettings
Forum Updated to NodeBB v4.3 + New Features

Problem with my WriteFunc for QSettings

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.9k 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.
  • K Offline
    K Offline
    keke222
    wrote on last edited by
    #1

    Hi everyone ! I'm here because I have some problems with WriteFunc for QSettings. I'm trying to use a XML file for QSettings but my problem is that the QIODevice given by the function call is empty.
    Worse, every time my function is call, the file is erased.
    My function :
    @bool writeXML(QIODevice &device, const QSettings::SettingsMap &map)
    {
    QTextStream out(&device);
    QDomDocument doc;

    QMap<QString, QVariant>::iterator i = map.begin();
    
    for(i; i != map.end(); ++i)
    {
        if(i.key() == "HardMode")
        {
            QDomElement HardMode = doc.createElement("HardMode");
            QDomElement time = doc.createElement("time");
            time.appendChild(doc.createTextNode(i.value().toString()));
    
            HardMode.appendChild(time);
            doc.appendChild(HardMode);
        }
        else
        {
            QStringList groupAndTable = i.key().split("/");
    
            QDomElement Mode = doc.createElement(groupAndTable.at(0));
            QDomElement time = doc.createElement("time");
            time.setAttribute("table", groupAndTable.at(1));
            time.appendChild(doc.createTextNode(i.value().toString()));
            Mode.appendChild(time);
    
            doc.appendChild(Mode);
        }
    }    doc.save(out, 4);
    return true;
    

    }
    @

    I believed that Qt managed the "merge" between datas in file and datas which was written in the empty QIODevice given by the function call or that Qt gave the device pointing on the file with datas but no ! ^^
    So now, I ask you for know how do it.

    P.S : Don't take attention about my English... I'm french.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      your writeFunc MUST write all data in file, no merge are performed.

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        keke222
        wrote on last edited by
        #3

        Every time I wanna to add some values to the file or just modified a value, I have to rewrite all data without the file content ?

        Thank you for your interest =)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          [quote author="keke222" date="1367780127"]Every time I wanna to add some values to the file or just modified a value, I have to rewrite all data without the file content ?
          [/quote]

          The WriteFunc is used by QSettings to write file, so you MUST re-write full file contents on it.

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • K Offline
            K Offline
            keke222
            wrote on last edited by
            #5

            I thought that we could do what Qt does with the ini files : create a file and insert some key/value pairs in this file and we could modify or add new key/value pairs in the file... I'll have to make a custom class to do it so. Thank you for your help !

            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