[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Singelton from QObject
From:       Nahuel =?utf-8?q?Defoss=C3=A9?= <nahueldefosse () yahoo ! com ! ar>
Date:       2007-05-23 18:48:25
Message-ID: 200705231848.25876.nahueldefosse () yahoo ! com ! ar
[Download RAW message or body]

El Wednesday 23 May 2007 08:09:15 Paul Giannaros escribió:
> On Wednesday 23 May 2007 05:53:58 Nahuel Defossé wrote:
> > I saw in ActiveState page the folowing code to make a singleton:
> > class Borg:
> >     __shared_state = {}
> >     def __init__(self):
> >         self.__dict__ = self.__shared_state
> >     # and whatever else you want in your class -- that's all!
> >
> > And in all Qt classes I customize via inheritance I do the folowing:
> > class MyClass(QSomeName):
> > 	def __init__(self):
> > 		QSomeName.__init__(self)
> >
> > I want to make a config class that recives some signals, so I inhertit
> > from QObject. I did the folowing in the constructor...
> > def __init__(self):
> >     if self.__shared_state == None:
> >       QObject.__init__(self)
> >     self.__dict__ = self.__shared_state
> >
> > It seems to work, but I'm not sure. Have you ever tried to do something
> > like that?
>
> That is not a singleton, it is a borg -- you can have many different
> instances of a borg class but they all share the same state. Hypothetically
> it's a nice distinction but in practice, I find it's not really worth it.
> For my Qt singletons I just subclass from a QObject-based class and make
> sure I parent to qApp (especially when using C++ to avoid memory leaks
> easily), then carry on with normal singleton stuff.

Can you give me a simple exaple of that?

> > Thanks
> > _______________________________________________
> > PyQt mailing list    PyQt@riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic