[英]TypeError: QFileDialog.history(self): first argument of unbound method must have type 'QFileDialog'
I'm using PyQT and have already instantiated the class for my GUI. 我正在使用PyQT,并且已经为我的GUI实例化了该类。 I'm trying to find the history of files opened in my GUI. 我正在尝试查找在GUI中打开的文件的历史记录。
def plotButtonClicked(self):
lst = QFileDialog.history(self)
The above def
is called by another function which creates the whole GUI. 上面的def
由创建整个GUI的另一个函数调用。 I get the following error: 我收到以下错误:
TypeError: QFileDialog.history(): first argument of unbound method must have type 'QFileDialog'
Funny thing is I've been using the QFileDialog
in other functions. 有趣的是,我在其他函数中一直使用QFileDialog
。 Here's one instance where it works: 这是一个可行的实例:
fname = QFileDialog.getOpenFileName(self, 'Open File')
So why isn't the history()
method not working? 那么, history()
方法为什么不起作用?
QFileDialog.history
is not a classmethod (also called static function in C++). QFileDialog.history
不是类方法 (在C ++中也称为静态函数)。 For you to be able to call the method, you'd have to either pass the class as first argument (as the error says) or instantiate QFileDialog
before calling the method. 为了能够调用该方法,必须在调用该方法之前将类作为第一个参数传递(如错误所述)或实例化QFileDialog
。
The reason why QFileDialog.getOpenFileName
works is because it's a classmethod (static method), and as the doc says, it's a convenience static function . QFileDialog.getOpenFileName
之所以起作用,是因为它是一种类方法 (静态方法),并且正如文档所说,它是一种便捷的静态函数 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.