python TypeError:__init __()恰好接受4个参数(给定1个) [英] python TypeError: __init__() takes exactly 4 arguments (1 given)
本文介绍了python TypeError:__init __()恰好接受4个参数(给定1个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用用于QGIS的python插件.我正在使用python2.5和pyqt4.我的 init 方法有4个参数. window = DlgQueryBuilder(),m不传递任何参数.我的.py代码如下:
I am working with python plugins for QGIS.I am using python2.5 and pyqt4 .My init method takes 4 argument.When i am trying to display form using window = DlgQueryBuilder() ,m passing no arguments.My .py code is as follows:
class DlgQueryBuilder(QtGui.QMainWindow, Ui_Dialog):
def __init__(self, db, iface, parent):
QtGui.QMainWindow.__init__(self)
Ui_Dialog.__init__(self)
self.dialog = QtGui.QDialog(parent)
self.setupUi(self)
self.db = db
# ...
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = DlgQueryBuilder()
window.show()
sys.exit(app.exec_())
错误:
Traceback (most recent call last):
File "C:\rt_sql_layer_working\DlgQueryBuilder.py", line 1176, in <module>
window = DlgQueryBuilder();
TypeError: __init__() takes exactly 4 arguments (1 given)
我需要传递什么参数?
推荐答案
您需要传递__init__
方法声明中定义的db
,iface
和parent
自变量.
You need to pass the db
, iface
and parent
arguments, as defined in your __init__
method declaration.
这篇关于python TypeError:__init __()恰好接受4个参数(给定1个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文