I’ve been searching some code to delete/destroy the previous instance of pyside2 QDockWidget in 3ds max with no luck.Can anyone help me?
deleteLater method is probably what you’re looking for, should exist on any QObject instance.
Thank you for the answer.
I don’t think I could made the “.deleteLater” work properly. As in:
Above line of code did not work. As an instance of the “PydockName” widget stays both in viewport and between the toolbar shortcuts when I right click on any toolbar in 3ds Max’s view port.
(“PyDockName” string is not set by “.setWindowTitle” but with “.setObjectName” )
But when I set the widget’s parent to “None” it is gone from both the viewport and the shortcut menu. I don’t know if the widget still stays somewhere in the memory.
The Code for setting parent to none is:
Is it safe to use “.setParent(None)” or should I try to find another solution?
deleteLater doesn’t immediately delete the object, but will once control is returned to the event loop.
It seems odd that something is causing it to be ignored. But I’ve no experience in Max and how it handles the Qt integration.
If you’re going to go the
setParent(None) route, I’d also make sure to call
deleteLater on the object just to be sure that it and any child objects do eventually get deleted.
You need to close() the UI as well as setting the parent to None doesn’t remove it from it’s active scope.
deleteLater() will then Garbage Collect the pointer once there are no references left ( not assigned to an active variable ).
deleteLater is more of a c++ method as GC in c++ is manual. Python will handle pyside GC without a need to do it yourself. ( It is sometimes too aggressive and can end up running GC on a still active object )
I’ll try that.
There is an attribute that can be set that will also “delete” the window on close. From within your dialog/main window (this might be windows only however):
Thanks for the info.
WA_DeleteOnClose attribute set in the code. I guess setting parent to none will not give me any problems.
Hi, I also get in this trouble, and when I set the parent to None. I can still find the widget in QApplication.topLevelWidgets() . the deleteLater() works properly in Maya and MotionBuilder but Max. It is really weird