Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:45:59+00:00 2026-06-10T08:45:59+00:00

I have a QTextEdit component created in the main thread of my program then

  • 0

I have a QTextEdit component created in the “main” thread of my program
then I start another thread, which will be updating this QTextEdit every x seconds, but then I get this error:

QObject: Cannot create children for a parent that is in a different thread.

this is the way I’m doing it:

def initGui():
   #some gui components
   global txt_list

   txt_list = QtGui.QTextEdit(w)
   txt_list.resize(580,400)
   txt_list.move(50, 50)
   txt_list.setReadOnly(1)
   txt_list.setFont(font_consolas)
   #more gui components

def update_list():
   t_monitor = threading.Thread(target=monitor_vector)
   t_monitor.daemon = True
   t_monitor.setName('monitor')
   t_monitor.start()

def monitor_vector():
   #retrieve info...
   lock = threading.Lock
   lock = True
   txt_list.clear() #clear list, to set the new one
   txt_list.setText('updated list')
   lock = False

this two last lines of code give me the above mentioned error. Can someone give me a clue on how to handle this?

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:46:02+00:00Added an answer on June 10, 2026 at 8:46 am

    One of the main gotcha’s about Qt is that you cannot call any QWidget methods from any thread other than the main GUI thread. All of your communication must be done by emitting signals from the extra threads, which will forward to the main gui.

    To start, I see you are using globals, and a lack of the self keyword, so I assume you are not using classes. My example will incorporate a class example as well.

    This is example is bare bones, just like yours, outlining the direction you might want to take:

    from PyQt4 import QtGui, QtCore
    
    class MyWidget(QtGui.QWidget):
    
        def __init__(self, parent=None):
            super(MyWidget, self).__init__(parent)
    
            ...
            self.txt_list = QtGui.QTextEdit(self)
            self.txt_list.resize(580,400)
            self.txt_list.move(50, 50)
            self.txt_list.setReadOnly(1)
            self.txt_list.setFont(font_consolas)
            ...
            self.monitor = Monitor()
            self.monitor.updateText.connect(self._handleTextUpdate)
            self.monitor.update_list()
    
        def _handleTextUpdate(self, txt):
            self.txt_list.clear()
            self.txt_list.setText(txt)
    
    
    class Monitor(QtCore.QObject):
    
        updateText = QtCore.pyqtSignal(str)
    
        def update_list(self):
            t_monitor = Thread(self.monitor_vector, parent=self)
            t_monitor.daemon = True
            t_monitor.setName('monitor')
            t_monitor.start()
    
        def monitor_vector(self):
            ...
            self.updateText.emit('updated list')
    
    
    class Thread(QtCore.QThread):
    
        def __init__(self, fn, args, kwargs, parent=None):
            super(Thread, self).__init__(parent)
            self._fn = fn 
            self._args = args 
            self._kwargs = kwargs 
    
        def run(self):
            self._fn(*self._args, **self._kwargs)
    

    The main thing to notice is that the functions running in the thread are emitting signals. They have no knowledge of the QWidgets in the other classes. Your MyWidget class connects the signal to a slot that can update the QLineEdit. When the thread emits a signal, it will be queued into the main thread and executed by the receiving slot.

    I also created a simple QThread subclass that can take a function and args, replicating the way the standard lib Thread class works. You should stick to using QThread because it is a QObject subclass, and supports signals and can run an event loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
i have a QTextEdit document which size is different by every print. In the
I have this class: class CustomEdit : public QTextEdit { Q_GADGET public: CustomEdit(QWidget* parent);
Why doesn't drag and drop pictures work on this QTextEdit? I have tried everything.
Anyone have any Idea why I don't have this function (setTextFormat) in my QTextEdit
I'm trying to create QTextEdit with some text, and in this text I have
I have a program in Python with PyQt, designed to run on Windows. This
I have a form with a QTextEdit on it, which is called translationInput .
I have this code to demonstrate the problem: public static void main(String[] args) {
I have created two classes: Example1 and Example2 , which extends activity. Example1 contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.