Qt-interest Archive, January 2008
RE: use a global function as slot
Message 1 in thread
Create a Singleton class (Error, Debug, GlobalData or whatever) and refer to it via an instance function:
MySingleton * MySingleton::instance()
{
static MySingleton *instance = new MySingleton();
return instance;
}
(Note that this isn't thread safe.)
Then your code is:
QObject::connect(pointerToCaller, SIGNAL(destroyed()), MySingleton::instance(), SLOT(objectDied()) );
Sam Dutton
SAM DUTTON
SENIOR SITE DEVELOPER
200 GRAY'S INN ROAD
LONDON
WC1X 8XZ
UNITED KINGDOM
T +44 (0)20 7430 4496
F
E Sam.Dutton@xxxxxxxxx
WWW.ITN.CO.UK
P Please consider the environment. Do you really need to print this email?
-----Original Message-----
From: Bo Thorsen [mailto:bo@xxxxxxxxxxxxxxxxxxxxx]
Sent: Thursday 03 January 2008 08:19
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: use a global function as slot
On torsdag den 3. Januar 2008, Yong Taro wrote:
> Is there a way to use in a Qt app a global function as a slot ?
No. Slots are always on QObject instances.
Bo.
> this is what I'm trying to make it work:
>
> void objectDied()
> {}
>
> QMap< QObject*, AdditionalObjectProperties* > _objects;
>
> void registerForXxxxx( QObject* pointerToCaller ) {
> QObject::connect( pointerToCaller, SIGNAL(destroyed()),
> [somethingMustGoHere], SLOT(objectDied()) );
>
> _objects.append( pointerToCaller, new AdditionalObjectProperties()
> ); }
>
> thanks
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 2 in thread
thanks, did it the right way.
I guess it was obvious that I was doing some weird stuff, had to correct it.
Dutton, Sam wrote:
> Create a Singleton class (Error, Debug, GlobalData or whatever) and refer to it via an instance function:
>
> MySingleton * MySingleton::instance()
> {
> static MySingleton *instance = new MySingleton();
> return instance;
> }
>
> (Note that this isn't thread safe.)
>
> Then your code is:
>
> QObject::connect(pointerToCaller, SIGNAL(destroyed()), MySingleton::instance(), SLOT(objectDied()) );
>
>
> Sam Dutton
>
>
>
>
>
>
>
>
>
>
> SAM DUTTON
> SENIOR SITE DEVELOPER
>
> 200 GRAY'S INN ROAD
> LONDON
> WC1X 8XZ
> UNITED KINGDOM
> T +44 (0)20 7430 4496
> F
> E Sam.Dutton@xxxxxxxxx
> WWW.ITN.CO.UK
>
> P Please consider the environment. Do you really need to print this email?
> -----Original Message-----
>
> From: Bo Thorsen [mailto:bo@xxxxxxxxxxxxxxxxxxxxx]
> Sent: Thursday 03 January 2008 08:19
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: use a global function as slot
>
> On torsdag den 3. Januar 2008, Yong Taro wrote:
>
>> Is there a way to use in a Qt app a global function as a slot ?
>>
>
> No. Slots are always on QObject instances.
>
> Bo.
>
>
>> this is what I'm trying to make it work:
>>
>> void objectDied()
>> {}
>>
>> QMap< QObject*, AdditionalObjectProperties* > _objects;
>>
>> void registerForXxxxx( QObject* pointerToCaller ) {
>> QObject::connect( pointerToCaller, SIGNAL(destroyed()),
>> [somethingMustGoHere], SLOT(objectDied()) );
>>
>> _objects.append( pointerToCaller, new AdditionalObjectProperties()
>> ); }
>>
>> thanks
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body. List archive and information:
>> http://lists.trolltech.com/qt-interest/
>>
>
>
>
>
--
[ signature omitted ]
Message 3 in thread
Dutton, Sam wrote:
> Create a Singleton class (Error, Debug, GlobalData or whatever) and refer to it via an instance function:
>
> MySingleton * MySingleton::instance()
> {
> static MySingleton *instance = new MySingleton();
> return instance;
> }
>
> (Note that this isn't thread safe.)
>
It actually is thread-safe if your compiler uses the library interface
specified by the C++ ABI for thread-safe initialization of
function-scope static variables. Gcc has supported this since version
4.0. It has also been backported to earlier versions of gcc included by
some linux distros (notably redhat). I don't think it is safe with msvc.
http://gcc.gnu.org/gcc-4.0/changes.html
Thomas
--
[ signature omitted ]