user3532371
user3532371

Reputation: 37

PyQt4 calling Method from another Class

I got Class A with the method i want to call.

class Class_A(QtGui.QMainWindow):
    def __init__(self, database, tableName):
        QtGui.QWidget.__init__(self)
        self.dbu = database_manager_2.DatabaseUtility(database, tableName)
        self.setupUi(self)

    def setupUi(self, Class_A):
         ...

    def print_somethig (self):
           print 'hello' 

This is class B :

class class B(object):              
    def setupUi_1(self, Dialog):
        ...
        self.my_instance = Class_A()
        QtCore.QObject.connect(self.pushButtonSecond, QtCore.SIGNAL(_fromUtf8("clicked()")),self.my_instance.print_something() )

As you can see i have created an instance from class A so i can call it's method in class B.

I got this error :

TypeError: __init__() takes exactly 3 arguments (1 given)

I know this is something related to OOP.

Upvotes: 0

Views: 571

Answers (1)

ProgrammingIsAwsome
ProgrammingIsAwsome

Reputation: 1129

That's nothing related with OOP:

Your method signature is:

def __init__(self, database, tableName):

So if you call: a = Class_A() you give just 1 parameter (self is implicitly given as a parameter). There is no to overcome it. You could define default values like that:

def __init__(self, database=None, tableName=None):

So if you call:

a = Class_A()

database and tableName will be None. But then:

self.dbu = database_manager_2.DatabaseUtility(database, tableName)

throws an error I think.

But with your original method signature, there is no way around that.

Upvotes: 1

Related Questions