# About the Qtimer and QTextBrower

**URL:** <https://discourse.slicer.org/t/about-the-qtimer-and-qtextbrower/9946>\
**Category:** Development\
**Created:** [January 25, 2020, 5:29pm UTC](https://discourse.slicer.org/t/about-the-qtimer-and-qtextbrower/9946 "2020-01-25T17:29:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [January 25, 2020, 5:29pm UTC](https://discourse.slicer.org/t/about-the-qtimer-and-qtextbrower/9946/1 "2020-01-25T17:29:07Z")

</div>

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):
  try:
    self.data += 1
    if self.data:
      print ('recv:',self.data)
      self.text.insertPlainText(self.data)
   except Exception as ex: 
    print (ex)
```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 25, 2020, 5:57pm UTC](https://discourse.slicer.org/t/about-the-qtimer-and-qtextbrower/9946/2 "2020-01-25T17:57:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [January 26, 2020, 4:35am UTC](https://discourse.slicer.org/t/about-the-qtimer-and-qtextbrower/9946/3 "2020-01-26T04:35:33Z")

</div>

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

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

But another problem is there is a slowly runing

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 26, 2020, 4:50am UTC](https://discourse.slicer.org/t/about-the-qtimer-and-qtextbrower/9946/4 "2020-01-26T04:50:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [January 26, 2020, 10:40am UTC](https://discourse.slicer.org/t/about-the-qtimer-and-qtextbrower/9946/5 "2020-01-26T10:40:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 26, 2020, 12:04pm UTC](https://discourse.slicer.org/t/about-the-qtimer-and-qtextbrower/9946/6 "2020-01-26T12:04:35Z")

</div>

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](https://github.com/pzaffino/SlicerArduinoController) for simple single-threaded serial communication implementation or [Plus toolkit](https://www.plustoolkit.org) for multi-threaded, networked configuration (communicate with many Arduinos, potentially connected to other computers - not directly to the one that runs Slicer).
