parse items of QTreeWidget into file/QSettings
Good morning everyone
does anyone know how to parse the items of a QTreeWidget into a file?
Im trying to save the list of items in QTreeWIdget with QSettigns but currentItem()->text(0);
works only for one item
Iv tried to do : selectAll(); and then currentItem()->text(0) but it freezes my program..
Some samples Ive tried
Trying to parse the items on QSettings value
Code:
treeWidget->selectAll();
settings.setValue("repositoriesLastState",treeWidget->currentItem()->text(0));
the above on freezes my program, segmentation fault....
Trying to parse the items on a file for futher processing later.
Code:
QFile repos
("/tmp/repositories");
repoList << treeWidget->currentItem()->text(0);
repos.close();
the above write to /tmp/repositories file only one item
Please help, thank you :)
Re: parse items of QTreeWidget into file/QSettings
ive managed to do the following:
Code:
//where "repoList" is my treeWidget
QFile repositories
("/tmp/repositories");
repositories.
open(QFile::WriteOnly |
QFile::Truncate);
int count =
parent ? parent->childCount() : repoList->topLevelItemCount();
for (int i = 0; i < count; i++)
{
parent ? parent->child(i) : repoList->topLevelItem(i);
// do something with the item
repositoryList << repoList->topLevelItem(i)->text(0);
}
repositories.close();
I found the above code in an old thread of qt-interest
The thing is, that even if the above code works nicely, saves my items in one line.
for example, my items in the QTreeWidget is like this:
Code:
test repo1
test repo2
test repo3
The above code saves it like this:
Code:
test repo 1test repo 2test repo 3
Ive tried to customize the code but no work...
any suggestions?
Re: parse items of QTreeWidget into file/QSettings
Well if you want linebreaks use:
Code:
repositoryList << "\n";
But you should consider using a XML or any other structured file (e.g. csv) to save your items...
Re: parse items of QTreeWidget into file/QSettings
ok now i feel stupid...
thank you :)