0

I want my output to appear in my pyqt textedit not python shell after clicking a pushbutton. I am not familiar with subprocess or stdout stuff and not even sure if this will involve them. Need some help here. Here is part of my code:

    self.textEdit = QtGui.QTextEdit(Dialog)
    self.textEdit.setGeometry(QtCore.QRect(20, 200, 431, 241))
    self.textEdit.setObjectName(_fromUtf8("textEdit"))

def readI2C(self):
    data = i2c.read_byte(0x50)
    return data
    self.textEdit.setText(data)

This code does not print anything. I tried it with print data but this prints result in python shell. Anyone can help?

Viv91
  • 45
  • 2
  • 8

1 Answers1

2

Place this line self.textEdit.setText(data) before return data. Once you return value from method, lines after return will not execute.

Also, if you're going to use textEdit only for output (not for editing) set self.textEdit.setReadOnly(1)

Aleksandar
  • 3,541
  • 4
  • 34
  • 57
  • I put `self.textEdit.setText(data)` and `self.textEdit.setReadOnly(1)` before `return data` but now I received an error: `TypeError: QTextEdit.setText(QString): argument 1 has unexpected type 'int'` – Viv91 Jul 22 '14 at 06:25
  • it means `data` is integer type and method `setText` needs QString type. fix it to be `self.textEdit.setText(str(data))` – Aleksandar Jul 22 '14 at 06:42