KConfig::addConfigSources is broken

Andreas Pakulat apaku at gmx.de
Mon Nov 19 12:33:54 GMT 2007

On 19.11.07 11:58:52, Andreas Pakulat wrote:
> On 18.11.07 22:52:05, Thomas Braxton wrote:
> > On 11/18/07, Andreas Pakulat <apaku at gmx.de> wrote:
> > > Yeah, actually I don't care which file I have to use in the openConfig()
> > > and which file to use in the addConfigSources as long as the symmetry is
> > > kept.
> > 
> > I tested this, and the symmetry is still there. Try my previous
> > suggestion and if it still doesn't work, then we have a bug, which
> > I'll gladly fix. I don't see how opening one file, then expecting
> > writes to go to a different file is symmetrical, or sensible. But, if
> > that's the way you want it I can easily change it.
> Sorry for not testing it earlier, so I did that switch now and have:
> d->m_cfg = KSharedConfig::openConfig( d->developerTempFile );
> d->m_cfg->addConfigSources( QStringList() << d->projectTempFile );
> KConfigGroup projectGroup( d->m_cfg, "Project" );
> QString managerSetting = projectGroup.readEntry( "Manager", "KDevGenericManager" );
> And projectTempFile contains the Project group with an entry for
> "Manager" thats not "KDevGenericManager"
> When I now start KDevelop and let it load the project, I get a happily
> cycling KDevelop at 90% CPU, because its using the KDevGenericManager
> and not the Manager plugin that is stated in the projectTempFile.

I did some testing with a simple App (generated from kapptemplate) and I
think these are the problems when using the way Thomas suggested:

- readEntry only reads from the file that the config was created (i.e.
  the one given to openConfig.
  Reading an entry that is in both files returns the value from the file
  that the config was created with, reading an entry that only exists in
  the file that was added, results in getting the default value given to

- writing out a new group doesn't work at all, using
    KConfigGroup newgrp( cfg, "NewGroup" );
    grp.writeEntry( "NewEntry", "NewValue");

  doesn't create a new group in the file that the config was opened

The code I added to the app (in the KMainWindow subclass constructor)
    KSharedConfig::Ptr cfg = KSharedConfig::openConfig( "/home/andreas/temp/developerFile" );
    cfg->addConfigSources( QStringList() << "/home/andreas/temp/projectFile" );

    KConfigGroup grp( cfg, "TestGroup" );
    QString dev = grp.readEntry("DevEntry", "Default");
    QString proj = grp.readEntry("ProjectEntry", "Default");

    kDebug() << "Read DevEntry:" << dev;
    kDebug() << "Read ProjEntry:" << proj;
    kDebug() << "Read ProjOnlyEntry:" << grp.readEntry("ProjectOnlyEntry", "Default");

    grp.writeEntry("NewEntry", "NewValue");

    KConfigGroup newgrp( cfg, "NewGroup" );
    grp.writeEntry( "NewEntry", "NewValue");

Using the two attached files as starting point.

So writing out new values to an existing group works and due to the
missing reading of values from the added config files preferring the
entries from the file that the config was opened with works as well.

I hope that this helps finding the actual bugs, I'd like to avoid having
to dig into KConfig myself ;)


You are magnetic in your bearing.
-------------- next part --------------
-------------- next part --------------

More information about the kde-core-devel mailing list