[PyQt] Problem regarding setting text of QTextEdit in a separate
thread
Shine Jose
shinejose22 at gmail.com
Thu Jul 9 14:25:55 BST 2009
Thanks a lot guys for your help ..... It worked out just fine after
implementing your suggestions. The wiki link especially was quite useful.
On Wed, Jul 8, 2009 at 6:07 PM, Hazen Babcock <hbabcock at mac.com> wrote:
> Shine Jose wrote:
>
>> Hello friends,
>> I am writing an application to read data from serial port and display it
>> on the screen using a QTextEdit widget. Since I'll have to poll the serial
>> port to check for arrival of data, I have created the widgets in the main
>> thread of the program and created a separate thread for reading data.
>> However when I try to update text of TextEdit using its setText() method in
>> the new thread, I get the following error:
>> QObject: Cannot create children for parent that is in different thread
>>
>> Searching on the net made me realize that setting the text in a separate
>> thread is not supported in pyQT. Is there any work-around for this problem?
>> I request you to suggest me any alternative method to find a solution for my
>> problem.
>>
>
> One way is to have the thread generate a message signal that contains the
> new text & then connect the signal to the main program which handles
> updating the TextEdit.
>
> The thread would have something like this in its run loop:
> self.emit(QtCore.SIGNAL("newText(PyQt_PyObject)"), new_text)
>
> And the main program would have something like:
> self.connect(self.thread, QtCore.SIGNAL("newText(PyQt_PyObject)"),
> self.handleNewText)
>
> This is something that you might also be able to do with timers, which are
> little simpler to use.
>
> -Hazen
>
>
--
Regards,
Shine Jose
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090709/dd18c541/attachment.html
More information about the PyQt
mailing list