Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Cannot create children for a parent that is in a different thread
Forum Updated to NodeBB v4.3 + New Features

Cannot create children for a parent that is in a different thread

Scheduled Pinned Locked Moved Unsolved Qt for Python
9 Posts 3 Posters 917 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ay CH
    wrote on last edited by
    #1

    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
    
    jsulmJ 1 Reply Last reply
    0
    • A Ay CH

      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
      
      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Ay-CH said in Cannot create children for a parent that is in a different thread:

      thread_reading

      What are you doing here?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Ay CH
        wrote on last edited by
        #3

        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

        jsulmJ 1 Reply Last reply
        0
        • A Ay CH

          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

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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!

          JonBJ 1 Reply Last reply
          0
          • A Offline
            A Offline
            Ay CH
            wrote on last edited by
            #5

            during the 2nd pass my code is blocked in : self.interface_barcode.show() before if self.stackedBarcode!=None:

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @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!

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @jsulm said in Cannot create children for a parent that is in a different thread:

              @Ay-CH Please format your code properly.

              +1. Even more so for Python where the code as shown is not even legal....

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Ay CH
                wrote on last edited by
                #7

                @JonB how that ?

                jsulmJ JonBJ 2 Replies Last reply
                0
                • A Ay CH

                  @JonB how that ?

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • A Ay CH

                    @JonB how that ?

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #9

                    @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.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved