[partial solved] How emit SIGNAL
-
wrote on 8 Oct 2015, 10:07 last edited by Franckynos 10 Aug 2015, 15:46
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(); }
-
wrote on 8 Oct 2015, 10:53 last edited by
@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.
-
wrote on 8 Oct 2015, 13:04 last edited by
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.
wrote on 8 Oct 2015, 13:23 last edited bybut 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.
wrote on 8 Oct 2015, 13:37 last edited by@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.
1/7