tags:

views:

70

answers:

2

Hi, I want to execute a slot in different class. Is it possible

 UI_CDSK Obj;
 connect(Obj.penDrive,SIGNAL(clicked()),this,SLOT( Obj.caller()));

This code is in different class and from this class i want to execute slot of different class(UI_CDSK )

Here penDrive and caller belongs to function UI_CDSK class and the mentioned code is in other class

+3  A: 

It's a little difficult without knowing the internals of UI_CDSK, but the correct syntax should be:

connect( Obj.penDrive, SIGNAL(clicked()), Obj, SLOT(caller()) );

So long as caller() is a public slot in UI_CDSK.

kurige
I gave like this but again showing errorMy slot is public onlyERROR cannot convert parameter 3 from 'UI_CDSK' to 'const QObject *
A: 

The connect method takes a pointer as receiver object, so if Obj isn't a pointer to a UI_CDSK object :

connect(Obj.pendrive, SIGNAL(clicked()), &Obj, SLOT(caller()));

Also this is probably already done (otherwise your compiler would have complained), but to use Qt signal slots mechanism, your UI_CDSK class must inherit from QObject.

It looks like the slot doesn't need to be public.

Leiaz
I inherited QObject in UI_CDSK When i called caller using another slot in same class its working fine
Thanks for the heads up - I had no idea slots did not have to be public when used in the Qt Signal/Slot context.
kurige