[partial solved] How emit SIGNAL
-
Hi,
I have a problem with my code.
I use some card "Yoctopuce" write in c++.
The library work with callback.
I want emit signal when callback arrived.
For define a callback i do this :YVoltage* volt = YVoltage::FindVoltage(target + ".voltage"); volt->registerValueCallback(mycall);
void mycall(YSensor *volt, const string& value) { qDebug() << "plop" << volt->get_module()->get_serialNumber().c_str() <<value.c_str(); //emit COCO(); }
but my function call (callback) is not member of my Qt class so I can't emit signals... who can I do this ?
The parameters of registerValueCallback is (
virtual int registerValueCallback(YVoltageValueCallback callback);
)
and YVoltageValueCallback is (typedef void (*YVoltageValueCallback)(YVoltage *func, const string& functionValue);
)Someone can help me ?
-
If I understand you right you already have a class derived from QObject. In this case you can use an instance of that class to emit a signal:
void mycall(YSensor *volt, const string& value) { myClassInstance.foundVoltage(); } void MyClass::foundVoltage() { emit mySignal(); }
-
@jsulm said:
myClassInstance
not really I have no access to QObject or Q ... something in mycall, it's a "volatile" function.
it's a callback so pointer of function.
If I try to insert mycall in My class the library yoctopuce says:
Impossible to convert Motor::* in YVoltageValueCallback
volt->registerValueCallback(&Motor::mycall)
-
@jsulm said:
myClassInstance
not really I have no access to QObject or Q ... something in mycall, it's a "volatile" function.
it's a callback so pointer of function.
If I try to insert mycall in My class the library yoctopuce says:
Impossible to convert Motor::* in YVoltageValueCallback
volt->registerValueCallback(&Motor::mycall)
@Franckynos But in your function you can call any public methods of any class instance, you just need access to such an instance.
-
You can implement observer pattern.
-
@Franckynos But in your function you can call any public methods of any class instance, you just need access to such an instance.
but the function is static but I'll tried to do something with pointer...
-
@Franckynos But in your function you can call any public methods of any class instance, you just need access to such an instance.
@jsulm I have declared a pointer to my class to have access at the instance and it works! I found this methode not really good with static member but for the moment I have juste this solution.