Issue
I would like to have a pyqt signal, which can either emit with a python "object" subclass argument or None. For example, I can do this:
valueChanged = pyqtSignal([MyClass], ['QString'])
but not this:
valueChanged = pyqtSignal([MyClass], ['None'])
TypeError: C++ type 'None' is not supported as a pyqtSignal() type argument type
or this:
valueChanged = pyqtSignal([MyClass], [])
TypeError: signal valueChanged[MyObject] has 1 argument(s) but 0 provided
I also tried None without the quotes and the c++ equivalent "NULL". But neither seems to work. What is it I need to do to make this work?
Solution
There are a couple of reasons why what you tried didn't work.
Firstly, the type
argument of pyqtSignal
accepts either a python type
object or a string giving the name of a C++ object (i.e. a Qt class).
So, to use None
as an argument type, you would have to pass type(None)
rather than the string "None"
.
Secondly, None
is special-cased to allow the default overload of the signal to be used without explicitly selecting the signature.
So if you created the signal like this:
valueChanged = QtCore.pyqtSignal([MyClass], [type(None)])
and then attempted to emit the signal like this:
self.valueChanged[type(None)].emit(None)
you would get an error like this:
TypeError: Window.valueChanged[MyClass].emit():
argument 1 has unexpected type 'NoneType'
So using valueChanged[type(None)]
would actually result in the default signature ([MyClass]
) being selected, which would then receive a mismatched argument of None
.
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.