Results 1 to 3 of 3

Thread: Can you send a signal from a static callback function?

  1. #1
    Join Date
    Aug 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Can you send a signal from a static callback function?

    Hello,

    I'm trying to figure out the syntax for how to achieve the following...

    From within a member function of a QWidget, I want to invoke a function in an external library which takes a callback as one of its arguments. I want the callback to be something which, when called, sends a signal which can be connected to one of the original QWidget's slots.

    The problem is that the callback can't be another member function of the same QWidget, but needs to be a static function of some sort (it could, I think, be a static function belonging to a class, but in most examples I've seen the callback is a stand-alone function not belonging to any class). However, since a static function (even if it belongs to a class) does not belong to an object, I can't see how I would connect a signal from it to my original QWidget's slot.

    Is there a way of doing this?

    Many thanks,
    Stephen.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can you send a signal from a static callback function?

    If you have a pointer to the class instance, you can connect as usual.

  3. #3
    Join Date
    Aug 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can you send a signal from a static callback function?

    Bingo! Of course you can. I've done precisely that in another application I've written within the past two months.

    D-oh!

    Thank you very much for the reminder.

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. static function emitting signal
    By wagmare in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2010, 08:34
  3. structs, pointer, static callback function
    By vonCZ in forum General Programming
    Replies: 3
    Last Post: 20th June 2008, 12:53
  4. Problem emitting signal from a static function
    By Valheru in forum Qt Programming
    Replies: 21
    Last Post: 12th June 2007, 14:48
  5. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47

Tags for this Thread

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.