Cannot create children for a parent that is in a different thread
-
Hello everyone,
I have an error on my barcode reader that I created on Qt, I make sense to launch a 3rd graphical interface which allows me to enter the name of the operator who is doing the test but the problem that happens to me is is that when I enter the operator name my application closes when I enter the name of the 2nd operator i.e. the cript will be processed twice, and I receive an error during the 2nd pass (Cannot create children for a parent that is in a different thread), that's why I would like to know if you have an idea to solve this problem of multithreading programming on Python.
This my code :
def startRead(self,msg="Scannez le code barre",not_testable="Non Testable",btn_ok="OK",btn_end="Fin des tests",barCode=None,quit="Fin des tests",echoMode=QLineEdit.Normal):
self.stopped_thread.wait() self.reading.release() self.stopped_thread.clear() self.stop_thread.clear() _thread.start_new_thread(thread_reading,(self,)) self.interface_barcode.textBarcode.setText(msg) if btn_ok!=None: self.interface_barcode.btn_ok.setText(btn_ok+" (Entree)") self.interface_barcode.btn_ok.show() else: self.interface_barcode.btn_ok.hide() if btn_end!=None: self.interface_barcode.btn_end.setText(btn_end+" (F4)") self.interface_barcode.btn_end.show() else: self.interface_barcode.btn_end.hide() if barCode!=None: self.interface_barcode.barcode.setText(barCode) self.interface_barcode.btn_ok.setShortcut(QKeySequence('Return')) self.interface_barcode.btn_end.setShortcut(QKeySequence('F4')) self.interface_barcode.show() if self.stackedBarcode!=None: self.previousWidget = self.stackedBarcode.setCurrentIndex(0) self.stackedBarcode.setCurrentIndex(self.wind_childBar) self.read_done.wait() self.stop_thread.set() self.read_done.clear() if self.lastButtonClicked=="b": code = self.code_barre self.interface_barcode.barcode.setText(self.code_barre) else: code = self.interface_barcode.barcode.text() self.interface_barcode.hide() if self.stackedBarcode!=None: self.stackedBarcode.setCurrentIndex(0) if self.lastButtonClicked=="q": raise errors.EndOfTest() return code -
Hello everyone,
I have an error on my barcode reader that I created on Qt, I make sense to launch a 3rd graphical interface which allows me to enter the name of the operator who is doing the test but the problem that happens to me is is that when I enter the operator name my application closes when I enter the name of the 2nd operator i.e. the cript will be processed twice, and I receive an error during the 2nd pass (Cannot create children for a parent that is in a different thread), that's why I would like to know if you have an idea to solve this problem of multithreading programming on Python.
This my code :
def startRead(self,msg="Scannez le code barre",not_testable="Non Testable",btn_ok="OK",btn_end="Fin des tests",barCode=None,quit="Fin des tests",echoMode=QLineEdit.Normal):
self.stopped_thread.wait() self.reading.release() self.stopped_thread.clear() self.stop_thread.clear() _thread.start_new_thread(thread_reading,(self,)) self.interface_barcode.textBarcode.setText(msg) if btn_ok!=None: self.interface_barcode.btn_ok.setText(btn_ok+" (Entree)") self.interface_barcode.btn_ok.show() else: self.interface_barcode.btn_ok.hide() if btn_end!=None: self.interface_barcode.btn_end.setText(btn_end+" (F4)") self.interface_barcode.btn_end.show() else: self.interface_barcode.btn_end.hide() if barCode!=None: self.interface_barcode.barcode.setText(barCode) self.interface_barcode.btn_ok.setShortcut(QKeySequence('Return')) self.interface_barcode.btn_end.setShortcut(QKeySequence('F4')) self.interface_barcode.show() if self.stackedBarcode!=None: self.previousWidget = self.stackedBarcode.setCurrentIndex(0) self.stackedBarcode.setCurrentIndex(self.wind_childBar) self.read_done.wait() self.stop_thread.set() self.read_done.clear() if self.lastButtonClicked=="b": code = self.code_barre self.interface_barcode.barcode.setText(self.code_barre) else: code = self.interface_barcode.barcode.text() self.interface_barcode.hide() if self.stackedBarcode!=None: self.stackedBarcode.setCurrentIndex(0) if self.lastButtonClicked=="q": raise errors.EndOfTest() return code@Ay-CH said in Cannot create children for a parent that is in a different thread:
thread_reading
What are you doing here?
-
thread_reading's code :
def thread_reading(self):
print("Thread Fucntion")
self.interface.flushInput();
_timeout=self.interface.timeout;
self.interface.timeout=0.5
code="";
while not self.stop_thread.isSet():
try:
code+=self.interface.read(endingCharacters=(END_CHAR,))
if (not self.reading.locked()) and (code[-1:]==END_CHAR):
self.reading.acquire()
log_instrument.write("Rx Code : " +repr(code))
self.code_barre=code[0:-1]
log_instrument.write("Xform Code : " +repr(self.code_barre))
self.lastButtonClicked="b"
self.read_done.set();
except: pass;
self.interface.timeout=_timeout
self.stopped_thread.set()
return -
thread_reading's code :
def thread_reading(self):
print("Thread Fucntion")
self.interface.flushInput();
_timeout=self.interface.timeout;
self.interface.timeout=0.5
code="";
while not self.stop_thread.isSet():
try:
code+=self.interface.read(endingCharacters=(END_CHAR,))
if (not self.reading.locked()) and (code[-1:]==END_CHAR):
self.reading.acquire()
log_instrument.write("Rx Code : " +repr(code))
self.code_barre=code[0:-1]
log_instrument.write("Xform Code : " +repr(self.code_barre))
self.lastButtonClicked="b"
self.read_done.set();
except: pass;
self.interface.timeout=_timeout
self.stopped_thread.set()
return@Ay-CH Please format your code properly.
Debug your app to see which line of your code leads to that issue.
In general the error you get means that you are creating an object in your thread whos parent lives in another thread. This is not allowed! -
@Ay-CH Please format your code properly.
Debug your app to see which line of your code leads to that issue.
In general the error you get means that you are creating an object in your thread whos parent lives in another thread. This is not allowed! -
This post is deleted!
-
@Ay-CH said in Cannot create children for a parent that is in a different thread:
@JonB how that ?
If you are asking how to format code blocks in posts here: where you enter your posts, look at the "toolbar" above it, there is a Code (
</>) icon. Or, put a line of just```(3 backticks) above & below your code blocks.