[PyQt] accessing variables of class

Enes Albay albayenes at gmail.com
Fri May 11 16:18:18 BST 2012


On 05/11/2012 05:47 PM, Vincent Vande Vyvre wrote:
> On 11/05/12 15:13, Enes Albay wrote:
>> Hi,
>>
>> when i change
>>
>> class A(QtGui.QMainWindow):
>>      ....
>>      def setupUI(self):
>>          self.lineEdit = QtGui.QLineEdit()
>>          self.b = B()
>>          self.b.c.clicked.connect(self.handleLetter)
>>          ...
>>
>>      def handleLetter(self):
>>          self.lineEdit.setText("Hello")
>>
>> there is no compilation or running error. But, lineEdit text doesn't
>> change, nothing happening.
>>
>>
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt

> Why don't you pass a reference of the main windows to your's subclass?

Because i am newbie :)

I am so pleased with all of your replies. This answer solve my problem.

I have one question more. Why this is useless:

class A(QtGui.QMainWindow):
     ....
     def setupUI(self):
         self.lineEdit = QtGui.QLineEdit()
         self.b = B()
     ...

     def handleLetter(self):
         self.lineEdit.setText("bla bla")                # ---> Notice: 
Difference is here


class B(QtGui.QWidget):
     ....
     def setupUI(self):
         self.C = C()
     ...

class C(QtGui.QPushButton):

     def __init__(self, parent, letter):
         self.clicked.connect(A.handleLetter)    # --->  Notice: Another 
difference

I get this error:

self.clicked.connect(A.handleLetter)
AttributeError: 'function' object has no attribute '__pyqtSignature__'







More information about the PyQt mailing list