PDA

View Full Version : problem with emiting a signal



msmihai
3rd January 2009, 14:18
Hello everybody. I'm just testing how to emit a custom signal . For example, i have a button and , when I press it, ai want a signal called MySignal to be emited. I've done that quite easy



emit MySignal();


I now declare this signal in the "h" file :



signals:
void MySignal();


The problem is in the "cpp" file where i define this signal:



void App1::MySignal()
{
}


When it compiles it gives the following error:



tmp/obj/release_shared/moc_app.o(.text+0x60):moc_app.cpp: multiple de
`App1::MySignal()'
tmp/obj/release_shared/app.o(.text+0x0):app.cpp: first defined here


What seems to be the problem ?

spirit
3rd January 2009, 14:25
you don't need to implement signal, the moc does it. you need just emit a signal like this


....
connect(myButton, SIGNAL(clicked()), this, SIGNAL(processButtonClick()));
....
void App::processButtonClick()
{
...
emit MySignal();
...
}

or in your case (of cource if you don't need to process a button click)


...
connect(myButton, SIGNAL(clicked()), myWidget, SIGNAL(MySignal()));
...

myWidget -- is the widget which has MySignal.

msmihai
3rd January 2009, 14:32
10x ... :) i didn't know that.