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. Make sure 'QTextCursor' is registered using qRegisterMetaType()
Qt 6.11 is out! See what's new in the release blog

Make sure 'QTextCursor' is registered using qRegisterMetaType()

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 2 Posters 4.3k 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.
  • C Offline
    C Offline
    Caeden
    wrote on last edited by Caeden
    #1

    Im sure you guys get this alot but im trying to thread and im getting this error:

    (Parent is QTextDocument(0x1243bfd4290), parent's thread is QThread(0x12437dd1260), current thread is myThread(0x1243c008470)
    QObject::connect: Cannot queue arguments of type 'QTextCursor'
    (Make sure 'QTextCursor' is registered using qRegisterMetaType().)```
    
    Can anyone help?
    
    My thread:
    
    ```class myThread(QThread):
        def __init__(self, username, _previous, text):
            
            super().__init__()
            self.username = username
            self._previous = _previous
            self.text = text
            print(dir(QThread))
    
        
        def run(self):
            
            n = len([k for k in _MESSAGE_COLLECTION.find({'msg': True})])
            while True:
                if n != len([k for k in _MESSAGE_COLLECTION.find({'msg': True})]):
    
                    self.message = _MESSAGE_COLLECTION.find_one({'_id': _ID + n})
                    
                    self.execute_update()
                    n += 1
    
        def execute_update(self):
            if self.message['from'] != self.username:
                self._previous.append(f'\n\n{self.message["from"]} says: {self.message["message"]}')
                self.text.setPlainText("\n".join(self._previous[::-1]))```
    
    and i call it with 
    
    

    self.thread = myThread(self.username, self._previous, self.text)
    self.thread.start()```

    eyllanescE 1 Reply Last reply
    0
    • C Caeden

      Im sure you guys get this alot but im trying to thread and im getting this error:

      (Parent is QTextDocument(0x1243bfd4290), parent's thread is QThread(0x12437dd1260), current thread is myThread(0x1243c008470)
      QObject::connect: Cannot queue arguments of type 'QTextCursor'
      (Make sure 'QTextCursor' is registered using qRegisterMetaType().)```
      
      Can anyone help?
      
      My thread:
      
      ```class myThread(QThread):
          def __init__(self, username, _previous, text):
              
              super().__init__()
              self.username = username
              self._previous = _previous
              self.text = text
              print(dir(QThread))
      
          
          def run(self):
              
              n = len([k for k in _MESSAGE_COLLECTION.find({'msg': True})])
              while True:
                  if n != len([k for k in _MESSAGE_COLLECTION.find({'msg': True})]):
      
                      self.message = _MESSAGE_COLLECTION.find_one({'_id': _ID + n})
                      
                      self.execute_update()
                      n += 1
      
          def execute_update(self):
              if self.message['from'] != self.username:
                  self._previous.append(f'\n\n{self.message["from"]} says: {self.message["message"]}')
                  self.text.setPlainText("\n".join(self._previous[::-1]))```
      
      and i call it with 
      
      

      self.thread = myThread(self.username, self._previous, self.text)
      self.thread.start()```

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @Caeden You should not directly modify the GUI in another thread.

      class myThread(QThread):
          text_changed = Signal(str)
      
          def __init__(self, username, _previous):
              super().__init__()
              self.username = username
              self._previous = _previous
      
          def run(self):
              n = len([k for k in _MESSAGE_COLLECTION.find({"msg": True})])
              while True:
                  if n != len([k for k in _MESSAGE_COLLECTION.find({"msg": True})]):
      
                      self.message = _MESSAGE_COLLECTION.find_one({"_id": _ID + n})
      
                      self.execute_update()
                      n += 1
      
          def execute_update(self):
              if self.message["from"] != self.username:
                  self._previous.append(
                      f'\n\n{self.message["from"]} says: {self.message["message"]}'
                  )
                  self.text_changed.emit("\n".join(self._previous[::-1]))
                  QThread.msleep(10)
      
      self.my_thread = myThread(self.username, self._previous)
      self.my_thread.text_changed.connect(self.text.setPlainText)
      self.my_thread.start()
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Caeden
        wrote on last edited by
        #3

        @eyllanesc ill try this, thank you!

        1 Reply Last reply
        1
        • C Offline
          C Offline
          Caeden
          wrote on last edited by Caeden
          #4

          @eyllanesc how can i pass variables through the emit? So i'm doing

          self.thread = myThread(self.username, self._previous, self.text)
                  self.myThread.text_changed.connect(self.settext)
                  self.thread.start()
          

          and

          def settext(self):
          

          but i dont know how i can pass the _message

          eyllanescE 1 Reply Last reply
          0
          • C Caeden

            @eyllanesc how can i pass variables through the emit? So i'm doing

            self.thread = myThread(self.username, self._previous, self.text)
                    self.myThread.text_changed.connect(self.settext)
                    self.thread.start()
            

            and

            def settext(self):
            

            but i dont know how i can pass the _message

            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by eyllanesc
            #5

            @Caeden It seems that you have not understood the usefulness or operation of the signals, I recommend you review the official docs. what is _message?

            If _message is a string then the slot must have the argument:

            foo_text = "Foo"
            self.text_changed.emit(foo_text)
            
            def settext(self, text):
                print(text)
            

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            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