How to provide C callbacks in a library
-
Hey all,
I don't have a ton of experience building libs. I was going to turn the core of my app into a static library, to re-use in some other projects. But the project includes vendor-provided SDK code (to interact with a piece of hardware) that needs to call C functions in the host app. Callbacks, I guess.
Currently these functions are in main.cpp as extern "C". I'm trying to isolate all of the functionality that relies on them (and a bunch of other functionality, like DB access) in the lib, which can offer up C++ objects to be used by a Qt Quick GUI. Is this feasible?
Thanks!
-
Hi
QML already expects you to do c++ back end for data and processing so
calling some SDK function and collect data from the callbacks is absolutely feasible and
also kinda expected in many use cases.
So yes, hide the callbacks and C function behind c++ classes exposing the data to QML via
properties or a model and it should work nicely. -
@Stokestack then simply put them in another C++ file and declare them as extern C.