[Qt-interest] parse items of QTreeWidget into file/QSettings

Mystical Groovy mysticalgr at gmail.com
Sun Nov 8 13:27:11 CET 2009


look what i've done and it actually works ;)

 QFile repositories("/tmp/repositories");
>
> repositories.open(QFile::WriteOnly | QFile::Truncate);
>
> QTextStream repositoryList(&repositories);
>
> QTreeWidgetItem *parent;
>
> int count =
>
> parent ? parent->childCount() : repoList->topLevelItemCount();
>
> for (int i = 0; i < count; i++)
>
> {
>
> QTreeWidgetItem *item =
>
> 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:

test repo1
> test repo2
> test repo3
>

The above code saves it like this:

test repo 1test repo 2test repo 3
>

Ive tried to customize the code but no work...
any suggestions?


2009/11/8 Ross Driedger <ross at earz.ca>

> Second try at sending this.
>
> On Sat, 07 Nov 2009 21:18:46 -0500, <qt-interest-request at trolltech.com>
> wrote:
>
> > Message: 2
> > Date: Sat, 7 Nov 2009 23:49:03 +0200
> > From: Mystical Groovy <mysticalgr at gmail.com>
> > Subject: Re: [Qt-interest] parse items of QTreeWidget into
> >
> > To: Andr? Somers <andre at familiesomers.nl>
> > Cc: qt-interest at trolltech.com
> > Message-ID:
> >       <4877b36e0911071349j140b502ftaac49ac20bb73e78 at mail.gmail.com>
> > Content-Type: text/plain; charset="windows-1252"
> > Oh god Thank you all for your replies again but I dont seem to find a
> > way to
> > manage this, I can access the model() of QTreeWidget thats for sure, but
> > then how can i parse the contents of it?(!!)
>
> This is pretty elementary computer science stuff.
>
> > I'm thinking that maybe its possible if somehow read the rows in
> > QtreeWidget
> > one by one, and for each row I get the item's text.
>
> If you have access to a tree item, you can:
> for each tree item you have selected
> 1) write the data to the file,
> 2) find the item's children
> 3) for each child, repeat the above two steps.
>
> > Mind if you share some sample code?
>
> I'm of mixed mind on this.  While it might help you for the immediate
> time, figuring it out how to do it (with some help) is the best way to
> learn.  I think I speak for many of the programmers here when I say that
> we had to do seemingly countless exercises in school on subjects like this
> -- and we became better programmers for it.
>
> You have been given a good number of helpful clues by several posters to
> the list.
>
> --
> "Without music to decorate it, time is just a bunch of boring production
> deadlines or dates by which bills must be paid."
> Frank Zappa
>
> Ross Driedger
> ross_at_earz.ca
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091108/5a28a944/attachment.html 


More information about the Qt-interest-old mailing list