python - How to kill a pure console application in PySide/PyQt? -


I am trying to convert from code (old-style) PyQt signals / slots to new-style PySide code . An example is a pure console application, which I have never done before. Unfortunately, when I try to run it several times, I have been told that the previous application is still going on.

This is a simple app: it basically lets you set a number, and if the number is new:

PyTrade Import from QtCore Import Class TaxRate (QtCore.QObject): rateChangedSig = QtCore.Signal (float) def __init __ (self): QtCore.QObject .__ init __ (self) auto rate = 17.5 DEF ART ART (self): return self. Set the DRT set (self, nuarett): if new! = Self. Rate: Self. Rate = NewRait itself Level changed SIG. (Self-rated) # twenty self imit (signal ("rate change", self rating) @ kytikore The slot () #Ttechnache does not really require DRF. Changed slot (value): Print ("tax rate {{.: 2f}%" is changed in format (value)) if __name__ == "__ main__ ": QtApp = QtCore.QCoreApplication (sys.argv) was QtGui.QApplication of #origional, but there is no GUI VAT = tax rate (vat.rateChangedSig.connect (rateChangedSlot) #was vat.connect (vat, signals (" Rate ") Vat.setRate (8.5) # will change (new rate is different) qtApp.quit () sys.exit (qtApp.exec_ ())

total Together, it works as expected, Do not kill the process except the last two lines when I try to run the program twice, the second time my IDE (spider) always tells me that it is already running in a different process. I try to run with, the window hangs.

Strangely, when I comment on the previous two lines, I do not get this warning. This is the opposite of what I expect (Based on past experience with puscious GUI applications)

After example on Zetcode, I have to go to qtApp.quit () with qtApp.instance () Tried to change Quit () Non-murder results

So, how do I kill this thing?

One idea is that I should not start it at first place (). Although it is a pure console app, the original program of summerfield starts with the ap = qtughui qs.y.b.c. , and it does not include the last two lines, things run fine, although sometimes There is no concern in it that every run will create a new process, so their programs seem to be effectively effective without warning? (In practice, I do not think it is happening on my system, so the answer is 'no' because I do not understand).

What is the correct way to start / control / kill a console application using PySide?

(This is ignoring the question, for some time, because Python will use any of the pure console applications in Python. But if anyone is interested in answering that different question If I have potentially relevant posts: < / P>

The problem is because you must call QCoreApplication.quit () before calling QCoreApplication.exec _ ( ) to call leaving in the event loop. It is not immediately, it happens immediately to the QCoreApplication.exec _ () call event loop that only calls when QCoreApplication.exit () (or QCoreApplication.quit () ) is created, while the event loop is running.

It has been explained to some extent but it is very easy to remember.

I think that you do not really need to call exec _ () as you are not using any event in your current code (Most of the event is with the window / mouse / keyboard, though you do not have anything in the future by QTimer ). It really depends on what you want to do with the program in the future. If you do not call exec_ () , then your script will exit because you would normally expect any python script (only the blocking function in your code call exec_ () , remove it and nothing is going on.)


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -