PyQt5 closeEvent reimplementation
-
btw, is there a way to pass command line arguments to a deployed app (sounds surreal but im asking)?
-
Do you mean like QCommandLineParser ? Or Python's argparse module ?
-
@user4592357
What do you mean about deployed app & argument passing? If by any chance you mean can you pass arguments once the app is launched from the desktop via a shortcut, then yes. In general, your PyQt app's__main__
seessys.argv
like normal. -
-
Can you give the reference ?
-
@SGaist
https://fatima-python.wikispaces.com/file/view/Rapid+GUI+Programming+with+Python+and+Qt.pdf
page 79 (book page, pdf page is 93) -
@user4592357
I wouldn't put anything as complicated as saving settings in a destructor. YourcloseEvent()
sounded right for this. Why are we suddenly discussing__del__()
? -
Because of this:
@SGaist said in PyQt5 closeEvent reimplementation:
Personally, I usually write down settings in the destructor of a class rather than close event.
That's what I do in C++.
-
@SGaist
Ohhh, didn't see that.Umm, far be it for me to disagree, but personally I wouldn't. I thought destructors were supposed to be cheap and have no side-effects. So many things can happen when saving settings. I wouldn't do it in C# FWIW, and I wouldn't do it in Python. (I also would not load settings in
__init__()
.) -
In the python case, that's indeed something debatable. Most of the time, people don't need to implement
__del__
.What I would do is to store the settings once you close the corresponding dialog so that you avoid the trouble you had with the unintended interruption you have (unless it's done while the dialog is open).
In the extreme case, you can even save you settings on modification if you have an "apply immediately" without cancel style of application preferences.