Hello Toni,

judging from the error message the problem ist not in the code you postet, 
but in the way you use the callback. Like the error message states: you 
shouldn't call methods of QObjects from other threads. Even if you don't 
use threads explicitly that happens easily if you use another 
framework/module that makes use of threads internally. So your callback is 
probably invoked in another thread.

You can work around that by using signals. 
Define your own signal...  for example 
my_signal = QtCore.pyqtSignal()


and in your callback function you trigger the signal 
my_signal.emit()


In your GUI code you connect your new signal with the update function 
my_signal.connect(lambda: self.text.setText('Hello world!')) 


If the concept is new to you, here's a tutorial: 
 
http://pythoncentral.io/pysidepyqt-tutorial-creating-your-own-signals-and-slots/
 
<http://pythoncentral.io/pysidepyqt-tutorial-creating-your-own-signals-and-slots/>


Regards
Sebastian


Am Donnerstag, 20. Juli 2017 14:49:18 UTC+2 schrieb Toni:
>
> Hi everyone,
>
> I'm trying to update the text inside a TextItem object from a callback, so 
> that I can stream float values that come from outside my python script.
> The problem I'm facing is that once my callback is invoked from the 
> framework I'm using, the following error is thrown:
>
> QObject: Cannot create children for a parent that is in a different thread.
>>
>
> I don't know how to avoid that and I'm not sure if there is actually a way 
> to do what I want,
>
> This is the code I have written until now:
>
> QtGui.QApplication([])
>         
> ## Create window with GraphicsView widget
>         
> win = pg.GraphicsLayoutWidget()
> win.show()  ## show widget alone in its own window        
> win.setWindowTitle('...')
>         
> # ... window settings
>         
> ## Create image item
> self.vis = pg.ImageItem()
>         
> # ... image settings        
>        
> ## Create obstacle histogram  
> plot = pg.PlotItem()
>        
> # ... plot settings
>
> self.text = pg.TextItem('Loading...')
> self.view.addItem(self.text)
>
>
> And from the callback mentioned above (where the problem is) I do:
>
> self.text.setText('Hello world!')
>
>
> Does anyone know how to avoid this problem and implement this behavior?
>
> Thank you in advance for your answers, I hope the question is clear.
>
>  
>
>
>        
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/cada55e3-e7f5-428f-813a-a75548ee19cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to