PDA

View Full Version : Signal in base class Slot in Subclass



csvivek
30th March 2008, 07:31
hi,
I have a code that works with a custom signal genreated by a class and then its handled by the same class only.

now i tried doing the same by genreating signal from the base class and then handle it with a slot at subclass but that is not working.

i have attached both the copies of the code..
please tell me what change i should do.

thanks in advance

jpn
30th March 2008, 09:59
First of all, subclass.h is missing define guards and the class declaration is missing a semi-colon (;). Furthermore, you do:


connect( pushButton_clear, SIGNAL( customSignal (const QString&) ), this, SLOT( mySlot(const QString&) ) );

Which doesn't compile either because pushButton_clear is a private member of the base class, thus inaccessible from the subclass. However, customSignal() is not a signal of the button anyway so you should change it to "this". Last but not least, you never create an instance of the subclass.

csvivek
30th March 2008, 15:54
OKie that was because the code was written in some other pc and i was not able to send the exact code which i tried.
---------------------------------------------------------------------------------!

now with those error being corrected!

Please tell me how to handle a signal emitted by a slot of one class, by a slot of some other class?

should i need to inherit the class that emits the signal or create an object of the class that emits the signal?

consider the following situation where i have a class that reads the socket for data.
whenever there is a data arrived at the port readyread() signal will be emitted and i connect this signal to the slot of the same class. This slots reads the header of the data. based on the header i l emit a signal.
This signal will be captured by any class that has a slot connected to this particular signal.
In this case who will be the sender of the signal to be filled in the connect call.

in genral if there is a base class slot that emits a signal how will i handle the signal thru the connect statement in the derived class?



connect(?,SIGNAL(baseclass signal1()),this,SLOT(onbaseclasssignal1())


I am a newbie to QT.

can anyone please enlighten me on this.....!

jpn
30th March 2008, 16:00
The sender is "this".

csvivek
30th March 2008, 16:03
i tried this but its not working

jpn
30th March 2008, 16:15
QObject::connect() outputs a warning to the debug output upon failed connections.

csvivek
30th March 2008, 16:42
no there is no such message coming at the terminal window...!
should i need to enable anything to get such messages ....!
can u pls b more brief with ur replies, so that i would be greatly benifited with it...

the pro file is in debug mode only.

thanks for ur patience...

jpn
30th March 2008, 16:59
Could you start with reading through this, please: Signals and Slots (http://doc.trolltech.com/4.3/signalsandslots.html)?