I am trying to code a static callback function that is called frequently from another static function within the same class. My callback function needs to emit
a signal but for some reason it simply fails to do so. I have put it under a debugger and the slot
never gets called. However when I place the code I used to emit
the data in a non-static function it works. Is there a reason I cannot emit a signal from a static function? I have tried declaring a new instance of the class and calling the emit function but with no luck.
class Foo
{
signals:
emitFunction(int);
private:
static int callback(int val)
{
/* Called multiple times (100+) */
Foo *foo = new Foo;
foo.emitFunction(val);
}
void run()
{
callback(percentdownloaded);
}
};
I have posted some basic code that demonstrates what I am attempting to do. I will post full code upon request.
Edit: I am posting the full code since this is kind of an odd scenario. http://pastebin.com/6J2D2hnM
.cpp
file that is called on a button press.void MainWindow::on_pushButton_clicked() { tProc = new Foo(this); connect(tProc, SIGNAL(ValChanged(int)), this, SLOT(onNumberChanged(int))); tProc->start(); }
it then creates a new instance of myFoo
class and starts the thread that calls the callback function. – UjijiMainWindow::on_pushButton_clicked()
function. Do I need to somehow re-connect it in the static function? – Ujijiclicked
function you connected your slot toone
Foo
, but incallback
you created another separateFoo
that knows nothing aboutfirst
foo. And you emit signal of this newFoo
, but signals of newFoo
are not connected to any slots. – Ivattsemit
from mystatic
callback function. The compiler won't let me call a non-static function (the emit) from a static function (callback). I tried to solve it by creating the new class. – Ujiji