Re: [Interest] QObject.destroyed() not working?!

2017-03-27 Thread Frank Rueter | OHUfx

Thanks Alexandru,

I will try it the way you suggest.

Cheers,
frank

On 27/03/17 9:59 PM, Alexandru Croitor wrote:

Hi,

I'm going to assume this is with PyQt.

Aside from what Thiago already mentioned, you could try to connect a method 
declared outside of the class scope.
So something like:

def myDestructor(obj):
   pass

class MyClass(object):
   def __init__(self):
   self.destroyed.connect(myDestructor)

Also do take into account that a Python object's destructor aka __del__ method 
might not be executed if the object is part of a cycle, due to the garbage 
collector not knowing the order in which destructors should be called.
I believe starting with Python 3.4, finalizers are always called.



On 27 Mar 2017, at 03:52, Frank Rueter | OHUfx  wrote:

Hi,

I'm pretty sure I'm misinterpreting how this should work so maybe you guys can 
help:

I have a QObject which I would like to run a simple clean up job just before 
it's destroyed.
I thought I could simply do this in it's constructor:
self.destroyed.connect(self.__cleanUp)

Then have self.__cleanUp() to the work.
However, a simple print statement inside self.__cleanUp() shows that it's never 
run.

What am I missing?

Thanks,
frank

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QObject.destroyed() not working?!

2017-03-27 Thread Frank Rueter | OHUfx

Thanks Thiago,

that makes sense.

Cheers,
frank

On 27/03/17 7:48 PM, Thiago Macieira wrote:

On domingo, 26 de março de 2017 18:52:48 PDT Frank Rueter | OHUfx wrote:

Hi,

I'm pretty sure I'm misinterpreting how this should work so maybe you
guys can help:

I have a QObject which I would like to run a simple clean up job just
before it's destroyed.
I thought I could simply do this in it's constructor:
  self.destroyed.connect(self.__cleanUp)

Then have self.__cleanUp() to the work.
However, a simple print statement inside self.__cleanUp() shows that
it's never run.

I don't speak Python, so I am answering in terms of C++:

QObject::destroyed() is emitted from QObject's own destructor. That means the
object, at the time, *IS* a QObject and not your class. There is no slot
called "__cleanUp" at that time anymore.

destroyed() is useful for another QObject to perform some actions, not for the
same object. If you need some actions to be performed at the time of
destruction, just put them in your class's destructor.



___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QObject.destroyed() not working?!

2017-03-27 Thread Thiago Macieira
On domingo, 26 de março de 2017 18:52:48 PDT Frank Rueter | OHUfx wrote:
> Hi,
> 
> I'm pretty sure I'm misinterpreting how this should work so maybe you
> guys can help:
> 
> I have a QObject which I would like to run a simple clean up job just
> before it's destroyed.
> I thought I could simply do this in it's constructor:
>  self.destroyed.connect(self.__cleanUp)
> 
> Then have self.__cleanUp() to the work.
> However, a simple print statement inside self.__cleanUp() shows that
> it's never run.

I don't speak Python, so I am answering in terms of C++:

QObject::destroyed() is emitted from QObject's own destructor. That means the 
object, at the time, *IS* a QObject and not your class. There is no slot 
called "__cleanUp" at that time anymore.

destroyed() is useful for another QObject to perform some actions, not for the 
same object. If you need some actions to be performed at the time of 
destruction, just put them in your class's destructor.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


[Interest] QObject.destroyed() not working?!

2017-03-26 Thread Frank Rueter | OHUfx

Hi,

I'm pretty sure I'm misinterpreting how this should work so maybe you 
guys can help:


I have a QObject which I would like to run a simple clean up job just 
before it's destroyed.

I thought I could simply do this in it's constructor:
self.destroyed.connect(self.__cleanUp)

Then have self.__cleanUp() to the work.
However, a simple print statement inside self.__cleanUp() shows that 
it's never run.


What am I missing?

Thanks,
frank

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest