简体   繁体   English

TypeError:QFileDialog.history(self):未绑定方法的第一个参数必须具有类型“ QFileDialog”

[英]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.

相关问题 TypeError:QPixmap.toImage():未绑定方法的第一个参数必须具有类型“ QPixmap” - TypeError: QPixmap.toImage(): first argument of unbound method must have type 'QPixmap' Python TypeError:必须以实例作为第一个参数调用未绑定方法 - Python TypeError: unbound method must be called with instance as first argument 如何解决我的pyqt程序中的错误(未绑定方法的第一个参数必须具有“ QDialog”类型)? - How to fix error in my pyqt programm (first argument of unbound method must have type 'QDialog') ? 必须使用instance作为第一个参数调用unbound方法 - unbound method must be called with instance as first argument TypeError:未绑定方法…实例作为第一个参数 - TypeError: unbound method…instance as first argument TypeError:必须使用“Class name”实例作为第一个参数调用unbound方法“method name”(改为使用str实例) - TypeError: unbound method “method name” must be called with “Class name” instance as first argument (got str instance instead) TypeError:未绑定方法“方法名称”必须以“类名称”实例作为第一个参数来调用(取而代之的是str实例) - TypeError: unbound method 'method name' must be called with 'class name' instance as first argument (got str instance instead) TypeError:未绑定的方法Date()必须以DateTime实例作为第一个参数来调用(取而代之的是int实例) - TypeError: unbound method Date() must be called with DateTime instance as first argument (got int instance instead) 如何修复TypeError:必须使用Dropper实例作为第一个参数来调用未绑定方法 - How to fix TypeError: unbound method must be called with Dropper instance as first argument TypeError:必须以c1实例作为第一个参数来调用未绑定方法fun1()(而是什么也不做) - TypeError: unbound method fun1() must be called with c1 instance as first argument (got nothing instead)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM