connect to a signal
-
Hi all,
I'm trying to connect to a signal as follows
connect(&api, SIGNAL(tetraGripEvent()), this, SLOT(eventHandler()));
But it says
No such signal tetra_grip_api::tetraGripEvent()
, let me explain the scenario:I have defined the signal in a class called
tetra_grip_api
as follows:void tetra_grip_reporter(STIM_GUI_TOPIC_T topic, uint8_t reg, uint32_t value) { emit api.tetraGripEvent(topic, reg, value); }
where
tetra_grip_reporter
need to be called from ac
file, so I defined it as:#ifdef __cplusplus extern "C" { #endif void tetra_grip_reporter(STIM_GUI_TOPIC_T topic, uint8_t reg, uint32_t value); #ifdef __cplusplus } #endif I don't know where I'm wrong. Any help would be welcome. Thanks in advance
-
@viniltc You need to have tetraGripEvent declared as signal in tetra_grip_api:
class tetra_grip_api : public QObject { Q_OBJECT signals: void tetraGripEvent(); }
The class has to be derived from QObject and have Q_OBJECT macro. See https://doc.qt.io/qt-5/signalsandslots.html
Does it look like this in your code? -
@viniltc said in connect to a signal:
I have defined the signal in a class called tetra_grip_api as follows:
And this is not a definition of a signal. Here you emit the signal.
Also, you're passing 3 parameters to the signal but in the connect your signals/slots do NOT have any parameters. -
@viniltc said in connect to a signal:
Do you mean to define as follows?
No
connect(&api, SIGNAL(tetraGripEvent(STIM_GUI_TOPIC_T, uint8_t, uint32_t)), this, SLOT(eventHandler(STIM_GUI_TOPIC_T, uint8_t, uint32_t)));
You have to specify the types of the parameters.
See the link I gave you.