Sijith
Sijith

Reputation: 3932

Execute Slot in different class

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

Upvotes: 0

Views: 960

Answers (2)

Leiaz
Leiaz

Reputation: 2917

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.

Upvotes: 0

kurige
kurige

Reputation: 3769

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.

Upvotes: 3

Related Questions