using KConfigGroupSave in kmainwindow

Simon Hausmann hausmann at kde.org
Sun Jan 19 17:10:20 GMT 2003


On Sun, Jan 19, 2003 at 05:29:10PM +0100, Tobias Koenig wrote:
> On Sun, Jan 19, 2003 at 04:25:09PM +0100, Simon Hausmann wrote:
> > On Sun, Jan 19, 2003 at 04:12:53PM +0100, Tobias Koenig wrote:
> Hi Simon,
> 
> > >      if (!configGroup.isEmpty())
> > > -       config->setGroup(configGroup);
> > > +       KConfigGroupSaver(config, configGroup);
> > >  
> > >      restoreWindowSize(config);
> > 
> > I doubt this patch works as expected because the KGS is first
> > constructed and then destructed right after that, with the relevant
> > code not being executed inbetween.
> Arghh... I should stop hacking and get some sleep :|
> 
> Is the attached patch ok?
> 
> Ciao,
> Tobias
> -- 
> In a world without walls and fences who
> needs Windows and Gates???

> Index: kmainwindow.cpp
> ===================================================================
> RCS file: /home/kde/kdelibs/kdeui/kmainwindow.cpp,v
> retrieving revision 1.89
> diff -u -b -p -r1.89 kmainwindow.cpp
> --- kmainwindow.cpp	13 Dec 2002 14:26:43 -0000	1.89
> +++ kmainwindow.cpp	19 Jan 2003 16:25:46 -0000
> @@ -704,8 +704,7 @@ void KMainWindow::applyMainWindowSetting
>      QStrList entryList;
>      int i = 0; // Number of entries in list
>  
> -    if (!configGroup.isEmpty())
> -       config->setGroup(configGroup);
> +    KConfigGroupSaver( config, !configGroup.isEmpty() ? configGroup : config->group() );
>  
>      restoreWindowSize(config);

Did you test your patch?

I'm asking because this does not what you want, I believe. The compiler will
generate code that will (again) just call the ctor and then the dtor.

Compare the output of

#include <qglobal.h>

struct Foo
{
    Foo() { qDebug( "Foo" ); }
    ~Foo() { qDebug( "~Foo" ); }
};

int main( int argc, char **argv )
{
    Foo();
    qDebug( "blah" );
    return 0;
}

against the output of

#include <qglobal.h>

struct Foo
{
    Foo() { qDebug( "Foo" ); }
    ~Foo() { qDebug( "~Foo" ); }
};

int main( int argc, char **argv )
{
    Foo blub;
    qDebug( "blah" );
    return 0;
}

Simon




More information about the kde-core-devel mailing list