PDA

View Full Version : static function emitting signal



wagmare
24th March 2010, 04:06
hi friends,
i am having an static call back member function in my QThread class which will be like our event handler for scanner device and in static void function how can i emit a signal to my base class GUI class..

when i try to emit a signal in .moc file its giving error in this pointer
here in static function i can use only static variable and functions so please suggest me a clear way to solve this problem ...

high_flyer
24th March 2010, 09:03
I guess that your call back is getting a "user param" parameter, which you use (or can use) to access objects out side the call back.
You can have one of these objects emit the signal for you there.

wagmare
25th March 2010, 03:04
I guess that your call back is getting a "user param" parameter, which you use (or can use) to access objects out side the call back.
You can have one of these objects emit the signal for you there.
thats the problem here ...

when the user place the finger on the device .. this call back call the print ("take off your finger") and after again it calls print ("put your finger") till enroll completes inside the callback function....

that time i cant use a common QString or emit a signal from the call back function ... please help me ...

wagmare
25th March 2010, 03:05
thanks for reply ...

high_flyer
25th March 2010, 08:52
What I meant was:
usually a call back will have a "user parameter" that allows you to "import" an object in to the call back like so:


void __stdcall myCallBack(..., unsigned int userParam){

MyClass *pMyClass = (MyClass*) userParam;

//Now you can call methods from 'MyClass', in which you can emit singnals too.
pMyClass->someSignalEmittingMethod();
}

wysota
25th March 2010, 09:32
If what high_flyer suggests isn't an option for you because of some obstacle (like the callback not providing the described ability) then you can have a singleton or a global object you can call from your callback and make that emit a signal from the object. What Daniel suggests would be a cleaner way to do it, though.

wagmare
26th March 2010, 04:18
What I meant was:
usually a call back will have a "user parameter" that allows you to "import" an object in to the call back like so:


void __stdcall myCallBack(..., unsigned int userParam){

MyClass *pMyClass = (MyClass*) userParam;

//Now you can call methods from 'MyClass', in which you can emit singnals too.
pMyClass->someSignalEmittingMethod();
}

thanks for reply
it simply crashed ... this is what i added

QtFpsThread *myclass = (QtFpsThread *)StateMask;
myclass->stateChange();

and the backtrace is

Segmentation fault
Register dump:

EAX: 00001000 EBX: 00f9f19c ECX: 0000000c EDX: 00000000
ESI: 00000002 EDI: 09622ab0 EBP: 07baced8 ESP: 07baced0

EIP: 00ece76e EFLAGS: 00010206

CS: 0073 DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 007b

Trap: 0000000e Error: 00000004 OldMask: 00000000
ESP/signal: 07baced0 CR2: 00000006

FPUCW: ffff037f FPUSW: ffff4020 TAG: ffffffff
IPOFF: 0073f2e9 CSSEL: 0073 DATAOFF: 00000000 DATASEL: 007b

ST(0) 0000 a8a8a8a8a8a8a8a9 ST(1) 0000 b9713d096b8536fe
ST(2) 0000 8000000000000000 ST(3) 0000 8000000000000000
ST(4) 0000 c000000000000000 ST(5) 0000 8000000000000000
ST(6) 0000 0000000000000000 ST(7) 0000 0000000000000000

Backtrace:
/usr/local/Trolltech/Qt-4.4.3/lib/libQtCore.so.4(_ZN11QMetaObject8activateEP7QObject PKS_iPPv+0x5a)[0xece76e]
??:0(_ZN11QtFpsThread13statusMessageERK7QString)[0x804f995]
./Qtfps(_ZN7QWidget5eventEP6QEvent+0xeac)[0x804c12c]
??:0(_ZN11QtFpsThread12UserCallBackEPvmPmmP10FTR_B ITMAP)[0x804caa3]
./libLinux/ftrapi.so(CheckResponse+0x60)[0x38a316]
./libLinux/ftrapi.so(CaptureFrame+0xf2)[0x38a723]
./libLinux/ftrapi.so(MTEnrollX+0x1a3)[0x38b4c4]
./libLinux/ftrapi.so(FTREnrollX+0x25)[0x38bd42]
./Qtfps(_ZN7QWidget5eventEP6QEvent+0xb01)[0x804bd81]
??:0(_ZN11QtFpsThread3runEv)[0x804c650]
/usr/local/Trolltech/Qt-4.4.3/lib/libQtCore.so.4(_ZN14QThreadPrivate5startEPv+0xb0)[0xdd1768]
/lib/libpthread.so.0[0x36a50b]
/lib/libc.so.6(clone+0x5e)[0x1255b2e]

Memory map:

00110000-00111000 r-xp 00110000 00:00 0 [vdso]
00111000-00114000 r-xp 00000000 08:02 3437369 /lib/libSegFault.so
00114000-00115000 r-xp 00002000 08:02 3437369 /lib/libSegFault.so
00115000-00116000 rwxp 00003000 08:02 3437369 /lib/libSegFault.so
00116000-0013b000 r-xp 00000000 08:02 3339255 /usr/lib/libpng12.so.0.22.0
0013b000-0013c000 rwxp 00025000 08:02 3339255 /usr



i think i have to register it ...

wagmare
26th March 2010, 04:24
If what high_flyer suggests isn't an option for you because of some obstacle (like the callback not providing the described ability) then you can have a singleton or a global object you can call from your callback and make that emit a signal from the object. What Daniel suggests would be a cleaner way to do it, though.
thanks for reply
but sorry i cant understand about singleton or global object .. please can u explain me more ... thanks again

wysota
26th March 2010, 08:34
http://en.wikipedia.org/wiki/Singleton_pattern
http://en.wikipedia.org/wiki/Global_variable