Results 1 to 9 of 9

Thread: static function emitting signal

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default static function emitting signal

    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 ...
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: static function emitting signal

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: static function emitting signal

    Quote Originally Posted by high_flyer View Post
    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 ...
    "Behind every great fortune lies a crime" - Balzac

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: static function emitting signal

    thanks for reply ...
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: static function emitting signal

    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:
    Qt Code:
    1. void __stdcall myCallBack(..., unsigned int userParam){
    2.  
    3. MyClass *pMyClass = (MyClass*) userParam;
    4.  
    5. //Now you can call methods from 'MyClass', in which you can emit singnals too.
    6. pMyClass->someSignalEmittingMethod();
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 25th March 2010 at 08:57.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: static function emitting signal

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: static function emitting signal

    Quote Originally Posted by high_flyer View Post
    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:
    Qt Code:
    1. void __stdcall myCallBack(..., unsigned int userParam){
    2.  
    3. MyClass *pMyClass = (MyClass*) userParam;
    4.  
    5. //Now you can call methods from 'MyClass', in which you can emit singnals too.
    6. pMyClass->someSignalEmittingMethod();
    7. }
    To copy to clipboard, switch view to plain text mode 
    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 ...
    "Behind every great fortune lies a crime" - Balzac

  8. #8
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: static function emitting signal

    Quote Originally Posted by wysota View Post
    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
    "Behind every great fortune lies a crime" - Balzac

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: static function emitting signal

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. how to emit signal in a static function ?
    By cxl2253 in forum Qt Programming
    Replies: 32
    Last Post: 7th July 2016, 21:36
  2. Problem emitting a signal
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2009, 00:56
  3. Emitting signal from DLL to EXE
    By Miihkali in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2009, 08:32
  4. emitting signals in const function
    By maxel in forum Qt Programming
    Replies: 3
    Last Post: 19th October 2008, 15:05
  5. Problem emitting signal from a static function
    By Valheru in forum Qt Programming
    Replies: 21
    Last Post: 12th June 2007, 14:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.