Qt “private slots:” what is this?

Slots are a Qt-specific extension of C++. It only compiles after sending the code through Qt’s preprocessor, the Meta-Object Compiler (moc). See http://doc.qt.io/qt-5/moc.html for documentation. Edit: As Frank points out, moc is only required for linking. The extra keywords are #defined away with the standard preprocessor.

PyQt Connect to KeyPressEvent

Create a custom signal, and emit it from your reimplemented event handler: class MyWidget(QtGui.QWidget): keyPressed = QtCore.pyqtSignal(int) def keyPressEvent(self, event): super(MyWidget, self).keyPressEvent(event) self.keyPressed.emit(event.key()) … def on_key(key): # test for a specific key if key == QtCore.Qt.Key_Return: print(‘return key pressed’) else: print(‘key pressed: %i’ % key) self.widget.keyPressed.connect(on_key) (NB: calling the base-class implementation is required in order … Read more

QT : Templated Q_OBJECT class

It is not possible to mix template and Q_OBJECT but if you have a subset of types you can list the slots and signals like this: class SignalsSlots : public QObject { Q_OBJECT public: explicit SignalsSlots(QObject *parent = 0) : QObject(parent) {} public slots: virtual void writeAsync(int value) {} virtual void writeAsync(float value) {} virtual … Read more