当前位置:网站首页>Some usage records about using pyqt5

Some usage records about using pyqt5

2022-06-25 15:09:00 Solution_ Cen

About use pyqt5 Some usage records

Environmental Science :Win10、Python3.7、Pyqt5 5.15
On the Internet pyqt5 There are not many detailed instructions for use , You can only try and error while using
Because it is an afterthought to record , I have to record some impressions I have encountered so far :

Detail related

1. The signal / Slot

To confirm and Pyqt5 The slot execution relationship between various form structures , Confirm the signal binding mode
The information found on the Internet says that signals can be activated through signals , Specific conditions have not been tested , At present, it is only clear that the following usage methods will make mistakes
Misuse :
 The wrong sample
In this case ,QtObjectB Of The signal B-1 Can't activate The signal A-1 Let's go QtObjectA Executive function A-1. Only by The signal B-1 Direct connection function A-1 For normal use ;
One of the ways that can be used successfully :
 The correct sample

2.Run The process , perform QtThread, Application error ( No problem during debugging )

The estimate here is python The issue of execution ;
Details :
The use of PyCharm Development ,Debug There is no problem when , but Run Execute individual addition when QtThread The program will flash back , Background display error -1073740791 (0xC0000409), No other information .
because Debug There will be no problems when , Only in every sentence print Let's see what went wrong , Finally, it was found that there was an error when starting and running the child thread ;
I wrote a new simple class IOThread Inherit QtThread, Mainly to undertake some IO Mission , Here, I will create and execute in one statement , There is no named variable to accept :

def IOFunc(*arg, **karg):
	#function
	pass

Class IOThread(QtThread)
	def __init__ (self, func, *arg, **karg):
		self.func = func
		self.arg = arg
		self.karg = karg
		
	def run(self)
		self.func(*self.arg, **self.karg)
		
Class ObjectA(QtObject):
...
	def FuncA(self):
		...
		IOThread(IOFunc, *Targ, **Tkarg).start()	#  This is written in PyCharm Run Will make mistakes , The written program will flash back 
		...
	def FuncB(self):
		...
		temp = IOThread(IOFunc, *Targ, **Tkarg)
		temp.start()	#  This is written in PyCharm Run Will make mistakes , The written program will flash back 
		...	
	def FuncC(self):
		...
		while True:
			#IOThread(IOFunc).start() #  This is written in PyCharm Run Will make mistakes , The written program will flash back 
			temp = IOThread(IOFunc, *Targ, **Tkarg)
			temp.start()	#  This is written in PyCharm Run No mistakes 
		...
	def FuncD(self):
		...
		self.temp = IOThread(IOFunc, *Targ, **Tkarg)
		self.temp.start()	#  This is written in PyCharm Run No mistakes 
		...
...

Judging from the above , Should be python Run When compiling the code, you create QtThread Then I thought I had run out , Reclaim memory at the end of the function , Make a mistake . You need to keep it in the function manually ;FuncC Yes means that if the task of a child thread is to manage 、 New thread , You can allow local variables to remain .

For the time being, I am impressed by the above 2022 year 2 month 18 Japan .

原网站

版权声明
本文为[Solution_ Cen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200510452764.html