Reputation: 97
The code:
from PyQt5 import QtWidgets
from PyQt5.QtGui import QClipboard, QGuiApplication
text = QClipboard.text(QClipboard.Clipboard)
And error information:
TypeError: arguments did not match any overloaded call:
QClipboard.text(QClipboard.Mode mode=QClipboard.Clipboard): first argument of unbound method must have type 'QClipboard'
QClipboard.text(str, QClipboard.Mode mode=QClipboard.Clipboard) -> (str, str): first argument of unbound method must have type 'QClipboard'
I want to write a program that can manage my OS clipboard's data.
How should I deal with the error?
Upvotes: 4
Views: 1449
Reputation: 120798
This is a basic python error which has nothing to do with PyQt. The traceback message states:
first argument of unbound method must have type 'QClipboard'
This is telling you that text()
is not a static or class method, and so it is expecting an instance of QClipboard
as the first argument (i.e. self
). So you can't call any of the methods of QClipboard
directly via the class object - you must use an instance.
The documentation for QClipboard makes it clear how it should be used:
QGuiApplication.clipboard().text()
And note that QGuiApplication.clipboard() is a static method, and so you can call it directly on the class object.
Upvotes: 3
Reputation: 1849
Based on the documentation, it seems like the first argument to .text(...) needs to be a unicode object! If you're simply trying to specify the mode, add the (mode=yourmode) keyword to the method call.
Upvotes: 0