PDA

View Full Version : Define and emit signals



ruben.rodrigues
23rd June 2010, 15:46
Hi all!

I saw how to define and emit signals but it is not quite working. I need to know if there is a problem to connect a slot to a signal from another class and emited by that other class.

So, I have a base class where my gui is handled and a client class where I do some tcp things.

on the client.h I simple define the signal like this:

signals:
void data_READY();

then on the base class I do:

Client *client = new Client();
connect(not_sure_what_to_set_here, SIGNAL(client->data_READY()),this,SLOT(login_data()));

1-Is it allowed to connect slots to signals from other classes?

if yes

2-What would be the first parameter on the connect?

tbscope
23rd June 2010, 16:17
Yes, it is allowed to connect slots and signals across class objects.

The first parameter is the sender of the signal, in your case that would be the object "client".
Example:


connect(client, SIGNAL(data_READY()), this, SLOT(login_data()));

Note also that SIGNAL is a macro to instruct the moc. The SIGNAL macro only takes the name of a function, not a pointer to a function.

ruben.rodrigues
24th June 2010, 12:50
Yes, it is allowed to connect slots and signals across class objects.

The first parameter is the sender of the signal, in your case that would be the object "client".
Example:


connect(client, SIGNAL(data_READY()), this, SLOT(login_data()));

Note also that SIGNAL is a macro to instruct the moc. The SIGNAL macro only takes the name of a function, not a pointer to a function.

Thank you! I just had time to test it now and it works fine. This also solve my other thread about using the QThread..