PDA

View Full Version : How to decide which SIGNAL to emit?



TheIndependentAquarius
22nd November 2011, 12:03
I have a joystick reader program. When a button of the joystick is pressed, a signal needs to be emitted.

How to choose which signal needs to be emitted?
Is there a list of the signals somewhere?

grin
22nd November 2011, 15:07
Hi, Anisha.
You can provide you own signal and appropriate slot for it.
For example


class CJoistikReader : public QObject
{
Q_OBJECT
public:
CJoistikReader(QObject*parent=0);
signals:
//you can emmit this signal, with button's id when appropriate button of joystik is pressed
void evButtonPressed(int button_id);
//-------- other methods and members of class -----
};

class CJoistikSignalReciver : public QObject
{
Q_OBJECT
public:
CJoistikSignalReciver(QObject*parent=0);
public slots:
// connect this slot to CJoistikReader::evButtonPressed(int) signal and process pressing
void processPressingButton(int button_id);
//-------- other methods and members of class -----
};


In QtGui model (though QApplication eventLoop) EVENTs (not signals) sending during about keyboadr and mouse manipulating (EKeyPressEvent, EMousePressEvent and so on). See QWidget documentation.

nightghost
22nd November 2011, 15:09
For each QObject class in Qt the signals are listed in the API, but you can always define as much custom signals as you want. Who is the receiver object of you signal? What should happen after the button press?