Signals must be declared using the "signals:" syntax in your class declaration. You didn't show anything really to tell us how you declared it.
Signals must be emitted through an instance of the class that declares them. So I do not think there is a way that you can invoke "emit' via a static method. The corresponding slot must be able to resolve the instance that sent the signal (via QObject::sender()) and with a static method, there is no sender.
Maybe if you showed a bit more context about what you are trying to do, we could provide some better advice. There are probably tricks you can use to map a static callback onto a member function of a class instance.
One way I can think of is to make your callback function a member of a struct that also contains a static member that points to a QObject class instance. Signals are just ordinary C++ methods, and "emit" pretty much maps to "this->", so in your static callback method in the struct you could simulate the emit in this way:
struct CallbackForwarder
{
static void myCallback()
{
if ( myInstance )
myInstance->doCallback();
}
static MyClass * myInstance = nullptr;
}
struct CallbackForwarder
{
static void myCallback()
{
if ( myInstance )
myInstance->doCallback();
}
static MyClass * myInstance = nullptr;
}
To copy to clipboard, switch view to plain text mode
and you would pass &CallbackForwarded:: myCallback as the address of your callback function to your processing interface. Depending on that interface, you might also be able to define the callback as a functor (operator()()) or as a lambda.
Bookmarks