Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to process signals in a Qt subclass?

How do I process a signal of in a subclass? Let's say my subclass is derived from QTextEdit and is interested in the signal textChanged. It seems silly to connect an object to itself, I should be able to simply override the textChange method -- but it isn't virtual.

What is the accepted way to do this?

like image 965
Tony the Pony Avatar asked Jun 09 '10 07:06

Tony the Pony


3 Answers

You can't implement/override a signal, so the only way is to create a new slot and connect it to textChanged():

connect( this, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)) );
like image 147
Frank Osterfeld Avatar answered Oct 19 '22 19:10

Frank Osterfeld


Maybe it seems silly, but that's the way I did it : connecting my derived class to the signal emited by the parent class.

But I'm interested if there are any other solutions !

like image 2
Jérôme Avatar answered Oct 19 '22 17:10

Jérôme


It is perfectly ok to connect a signal to a slot in the same class. So implement your slot and connect it to textChanged(QString)

like image 1
codinguser Avatar answered Oct 19 '22 19:10

codinguser