How to replace `connect(this, SIGNAL(frameSwapped())...` with modern version
-
@ankou29666 said in How to replace `connect(this, SIGNAL(frameSwapped())...` with modern version:
And wondering then what's the point in declaring slots
The old syntax used SIGNAL/SLOT macros to replace the functions with strings. Back then slots needed to be marked as slots because moc would only create mappings from the string to the function pointer for those methods. With the new syntax we are now using function pointers directly. So, for the connect call we don't have to qualify them as slots anymore. However, Qt also has some reflection built in. In these cases it could still make sense to declare some methods as slots. Though, to be honest, I haven't used that functionality in years...
-
@jeremy_k said in How to replace `connect(this, SIGNAL(frameSwapped())...` with modern version:
but suspect PyQt and PySide/Qt for Python do as well
I do not know how they implement "under the hood", but at least from a user perspective PyQt/PySide use a connection syntax "equivalent" to the new C++ style, referring to functions directly not through strings:
signallingObject.signal.connect(slotObject.slot) self.pushbutton.clicked.connect(self.onClicked)
-
@JonB said in How to replace `connect(this, SIGNAL(frameSwapped())...` with modern version:
@jeremy_k said in How to replace `connect(this, SIGNAL(frameSwapped())...` with modern version:
but suspect PyQt and PySide/Qt for Python do as well
I do not know how they implement "under the hood", but at least from a user perspective PyQt/PySide use a connection syntax "equivalent" to the new C++ style, referring to functions directly not through strings:
signallingObject.signal.connect(slotObject.slot) self.pushbutton.clicked.connect(self.onClicked)
Under the hood is what I was referring to. The python syntax isn't (IMHO of course) relevant to a question about a C++ implementation. The availability of the interface is.
Drifting off topic, I don't consider the python syntax equivalent to C++ function pointers. Detection of a nonexistant signal or slot doesn't happen until the initial runtime parse, and detection of incompatible arguments in the slot is delayed until slot invocation. For example:
... object = QObject() object.destroyed.connect(lambda x, y, z: print("QObject.destroyed() does not have 3 arguments")) print("No exceptions so far") del object # With PyQt: TypeError: <lambda>() missing 2 required positional arguments: 'y' and 'z'
-
@jeremy_k said in How to replace `connect(this, SIGNAL(frameSwapped())...` with modern version:
Detection of a nonexistant signal or slot doesn't happen until the initial runtime parse, and detection of incompatible arguments in the slot is delayed until slot invocation.
Which is how Python works compared against C++, regardless of Qt.
My comment about Python signal connections was just intended as an observation, about how it works at coding time using function (or whatever) calls rather than strings. User gets a language check that signal and slot functions exists (at runtime in Python, and hopefully something at editing time too).
-
@JonB said in How to replace `connect(this, SIGNAL(frameSwapped())...` with modern version:
@jeremy_k said in How to replace `connect(this, SIGNAL(frameSwapped())...` with modern version:
Detection of a nonexistant signal or slot doesn't happen until the initial runtime parse, and detection of incompatible arguments in the slot is delayed until slot invocation.
Which is how Python works compared against C++, regardless of Qt.
I agree. This is more like the string based connect.
My comment about Python signal connections was just intended as an observation, about how it works at coding time using function (or whatever) calls rather than strings. User gets a language check that signal and slot functions exists (at runtime in Python, and hopefully something at editing time too).
That's an IDE feature. My browser tells me when things that I type in a text input aren't in its dictionary. The words are still more like free strings than function pointers.