[Interest] Reading trees from QSettings

BRM bm_witness at yahoo.com
Thu Aug 30 15:37:48 CEST 2012


> From: Sensei <senseiwa at gmail.com>

>Hi again!
>
>As you remember, I was playing with QTreeWidget items, now I'd like to 
>write and read the tree (a strict tree) from QSettings.
>
>I can write the tree easily, for example the following tree has a file, 
>and a folder; the folder has a file inside.
>
>[Root]
>item\1\name=New File
>item\2\name=New Folder
>item\size=2
>
>[New%20Folder]
>item\1\name=aaaa
>item\size=1
>
>
>As I need to recreate files and folders, I need to check, for every item 
>in a group, if there exists a group with the same name. If so, then it's 
>a folder, a file otherwise.
>
>But, as you see from my output,  it fails the check:
>
>
>root is 0x104d7a470
>nodes is not empty
>reading size 2
>appending to Root (0x104d7a470) file New File
>appending to Root (0x104d7a470) file New Folder
>
>
>
>I am using the following (s being a QSettings):
>
>
>
>             if (s.childGroups().contains(name))
>             {
>                 qWarning("appending to %s (%p) folder %s", 
>qPrintable(target->data(0, 0).toString()), target, qPrintable(name));
>                 item = new QTreeWidgetItem(target, QStringList(name), 1);
>                 item->setFlags(item->flags() | Qt::ItemIsEditable);
>                 nodes.push_back(item);
>             }
>             else
>             {
>                 qWarning("appending to %s (%p) file %s", 
>qPrintable(target->data(0, 0).toString()), target, qPrintable(name));
>                 item = new QTreeWidgetItem(target, QStringList(name), 2);
>                 item->setFlags(item->flags() & (~Qt::ItemIsDropEnabled) 
>| Qt::ItemIsEditable);
>             }
>
>
>Is there a "safe" way of querying QSettings for an existing group?
>

While I don't know if there is a "safe way to [query] for an existing group", I'd suggest that you just give yourself another key as part of the array to identify it as either a file or group.

$0.02

Ben




More information about the Interest mailing list