Can I change the return type of a slot (such as class type or str or int)? And if that is possible, can I return two value like a normal function (such as (bool, str)
or (int, str)
)?
Code:
class SignalSlotTest(QObject):
get_str = QtCore.Signal(str)
get_bool_and_str = QtCore.Signal(str)
def __init__(self):
super().__init__()
def start(self):
msg = self.get_str.emit('start1')
print(f"start1 return : {msg}")
(is_valid, msg) = self.get_bool_and_str.emit('start2')
print(is_valid, msg)
class MainTest(QObject):
@QtCore.Slot(str, result = str) # question 1
def get_str_func(msg):
return ""
@QtCore.Slot(str, result=(bool, str)) # question 2
def get_bool_and_str_func(msg, msg2):
return (False,"return_message")
if __name__ == "__main__":
main_test = MainTest()
signal_slot_test = SignalSlotTest()
signal_slot_test.get_str.connect(main_test.get_str_func)
signal_slot_test.get_bool_and_str.connect(get_bool_and_str_func)
signal_slot_test.start()
When I tested the first question, return type is 'bool' type. (It prints True
).
And when I tested the second question, an error occurs:
TypeError: 'bool' object is not iterable
I don't know if my method is wrong...