PDA

View Full Version : how to check if a signal in emited or not??



sudhansu
14th December 2009, 08:45
Hi Every one,
in .h file, i defined a signal like

signals:
void mySig(arg list);-- assume it in a.h

in .cpp file inside a method i'm emitting the signal like

emit mySig(arg);

in another file, b.h
i've a slot

void mySlot(arg list same as mySig);

and inside b file constructor i'm connecting this mySig to mySlot.

How ll i ckeck that if that signal is emited or not? plz help.

spirit
14th December 2009, 08:55
add qDebug in that place where you emit a signal.

drizzt
14th December 2009, 08:56
i do not really understand what you mean, but if you only want to check if you code works,
type "qDebug() << "signal/slot works"; (or what ever) and run your code to test... you'll see if the signal and slot are really connected

squidge
14th December 2009, 09:06
Or just put a breakpoint on the signal and run the code. If the breakpoint is hit, the signal works.

sudhansu
14th December 2009, 09:45
add qDebug in that place where you emit a signal.

Thank you spirit for the reply. Actually i've declare the signal in .h but didn't define it in .cpp file.


a.h
a();
~a()
function();
signal:
void mySig(arg);// signal return type is void


and inside a function


a.cpp
function()
{
....
...
qDebug()<<"checking mySig";
emit mySig(arg);
qDebug()<<"mySig executed";
}

But is this the right way???

spirit
14th December 2009, 09:47
actually, you don't need to define signals in cpp, because moc do it for you.
this code is ok


a.cpp
function()
{
....
...
qDebug()<<"checking mySig";
emit mySig(arg);
qDebug()<<"mySig executed";
}

sudhansu
14th December 2009, 09:51
actually, you don't need to define signals in cpp, because moc do it for you.
this code is ok


a.cpp
function()
{
....
...
qDebug()<<"checking mySig";
emit mySig(arg);
qDebug()<<"mySig executed";
}


Thank you very much. and 1 more question. if i'm emitting the signal in a.cpp,
and in b.cpp


connect(a.obj, SIGNAL(mySig(arg)),this, SLOT(mySlot(arg)));

where mySlot(arg), is a public slot in b.h
Is this rightway to connect Signal and slot belongs from different class?