[Qt-interest] static function emitting signal

BRM bm_witness at yahoo.com
Wed Mar 24 15:32:50 CET 2010


Well you don't have to necessarily use a global variable - just something the static function can access:

- global variables
- file static variables (global but not fully global)
- class static variables
- function static variables (with combination of the parameters to initialize it)

Ben



----- Original Message ----
> From: Gabriel M. Beddingfield <gabrbedd at gmail.com>
> To: Chandru... <sekarwagmare at gmail.com>
> Cc: qt-interest at trolltech.com
> Sent: Wed, March 24, 2010 12:07:06 AM
> Subject: Re: [Qt-interest] static function emitting signal
> 
> 
Hi Chandru,

On Wed, 24 Mar 2010, Chandru... wrote:

> 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..
>
> here in static function i canuse only static variable 
> and functions so
> please suggest me a clear way to solve this problem 
> ...

A lot of callback API's will do something like this:

  
>    typedef void (*SomeCallbackType)(void* arg);
     int 
> register_callback(SomeCallbackType function, void* arg);

the 'arg' is a 
> handle to... anything you want.  When 
wrapping this sort of callback 
> API in C++, it's common to do 
this:

class Foo {
public:
  
>    Foo() {}

     static void _callback(void* arg) 
> {
         Foo* that = static_cast<Foo*>(arg);

>     that->my_callback();
    
> }

protected:
     void my_callback() {
    
>      // Do your real work here
     }
};

int 
> main()
{
     Foo f;
    
> register_callback(Foo::_callback, &f);

    
> //...
}

However, if the API you're using doesn't allow you to pass 
> 
an argument like this... you're going to have to use some 
manner of 
> global variable to get back to your class 
> 
instance.

HTH,
Gabriel
_______________________________________________
Qt-interest 
> mailing list

> href="mailto:Qt-interest at trolltech.com">Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list