You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, May 26th 2008, 10:56am

How to use signal slot ?

Hi,

I have a problem.......

I have two classes A and B.

There is a slot function in A add(). I want that when control reaches in add() it automatically called get() function in B without creating object of B in A.

Is this possible through signal and Slot.

If yes then how ??

Thanks

krsmichael

Trainee

  • "krsmichael" is male

Posts: 62

Location: California

Occupation: Software Engineer

  • Send private message

2

Monday, May 26th 2008, 7:17pm

RE: How to use signal slot ?

Hi,

I have a problem.......

I have two classes A and B.

There is a slot function in A add(). I want that when control reaches in add() it automatically called get() function in B without creating object of B in A.

Is this possible through signal and Slot.

If yes then how ??

Thanks
This is the WHOLE point of signals and slots.

In main.cpp

AClass* aClass = new AClass;
BClass* bClass = new BClass;

connect(aClass, SIGNAL(add), bClass, SLOT(get));

aClass does not contain a bClass and bClass does not contain an aClass.

  • "Code_Warrior" is male

Posts: 10

Location: Kiev,Ukraine

Occupation: Software developer

  • Send private message

3

Monday, May 26th 2008, 8:58pm

I want that when control reaches in add() it automatically called get() function in B without creating object of B in A.


I think, you can't use member-function of class without using object of that class. Solution of krsmichael is most easy in use, but you might use C++ key-word "Friend" function.
Det var engang en ridder bold en skjönn prinsesse og et troll.