KConfigGroup parent() and isValid()


KConfigGroup parent() currently always returns a KConfigGroup object with a
dptr. isValid() determines validity based on having a dptr. this leads to
loops like this:

KConfigGroup group = <some valid group>;
while (group.isValid()) {
group = group.parent();

to never terminate, as parent() returns the top level group forever (name =
"<default>"). this is because, due to the behavior of parent(), the top level
group is its own parent.

is it intended that the parent of the default group is itself?

this would not be so much of a problem is there was a way to test for the
group being the top level group without hardcoding magic literal strings like
"<default>" into the code.


Re: KConfigGroup parent() and isValid()

By =?utf-8?Q?Thoma... at 09/19/2014 - 11:28

I'm checking for existance rather than validity in kconfig (great tool, far superior to k(read|write)config, btw /advert ;-)

KConfigGroup group = <some EXISTING group>;
while (group.isValid()) {
group = group.exists();


Re: KConfigGroup parent() and isValid()

By Aaron J. Seigo at 09/21/2014 - 14:09

On Friday, September 19, 2014 17.28:04 Thomas Lübking wrote:
That's a nice work around; I still wonder about the existing API though.

Re: KConfigGroup parent() and isValid()

By =?UTF-8?Q?Nicol... at 09/19/2014 - 23:07

2014-09-19 12:28 GMT-03:00 Thomas Lübking <thomas. ... at gmail dot com>:
That code doesn't make sense. Did you mean:
while (group.exists()) {
group = group.parent();