11

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?

Tony the Pony
  • 40,327
  • 71
  • 187
  • 281

3 Answers3

12

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)) );
Frank Osterfeld
  • 24,815
  • 5
  • 58
  • 70
2

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 !

Jérôme
  • 26,567
  • 29
  • 98
  • 120
1

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)

codinguser
  • 5,562
  • 2
  • 33
  • 40