About the Qtimer and QTextBrower

I want to update the text in slicer extension by Qtimer and QTextBrower, but nothing happon after run the main(). The code as follows:

self.text= qt.QTextBrowser()  
parametersFormLayout2D.addRow("received:", self.text)

def main(self):
  qt.QTimer.singleShot(100, self.Reader)

def Reader(self):
    self.data += 1
    if self.data:
      print ('recv:',self.data)
   except Exception as ex: 
    print (ex)

Can you give a full example? It is not clear from your snippets how you use self.

The problem is qt.QTimer.singleShot().
I changed to

self.timer = qt.QTimer()
self.timer.connect(‘timeout()’, self.Reader)

But another problem is there is a slowly runing

What are you trying to achieve? Displaying real-time data that you receive via OpenIGTLink?

I try to connecte my single chip computer and display in slicer.
Can I use the Qthread in slicer to deal with the slow-problem? And is there any example for that?

You need to make sure that communication does not block the main thread for too long.

If you use serial (USB, RS-232,…) communication then you can use this work-in-progress Arduino extension for simple single-threaded serial communication implementation or Plus toolkit for multi-threaded, networked configuration (communicate with many Arduinos, potentially connected to other computers - not directly to the one that runs Slicer).

1 Like