0

I have this class:


class CustomEdit : public QTextEdit
{
    Q_GADGET

public:
    CustomEdit(QWidget* parent);

public slots:
    void onTextChanged ();
};


CustomEdit::CustomEdit(QWidget* parent)
    : QTextEdit(parent)
{
    connect( this, SIGNAL(textChanged()), this, SLOT(onTextChanged()));
}


void CustomEdit::onTextChanged ()
{
    // ... do stuff
}


The onTextChanged method is never called when I type text into the edit control.
What am I missing?

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281

3 Answers3

1

One additional possibility which I just took about a day to solve in my own code:

  • The signal is defined in a superclass AND its subclass. The connect() call was operating on a subclass pointer, but the signal was emitted from the superclass code. The solution was to remove the signal declaration from the subclass, which was there by mistake anyway.
Dave
  • 155
  • 1
  • 6
1

All classes that contain signals or slots must mention Q_OBJECT at the top of their declaration. They must also derive (directly or indirectly) from QObject.

Try using Q_OBJECT

Pardeep
  • 929
  • 6
  • 14
1

A couple of other possibilities:

1) The object you are emitting the signal from is blocked (see QObject::blockSignals())

2) The receiver has no thread affinity. If the thread object that the receiver was created in goes away and the receiver isn't moved to another thread, it won't process events (slots being a special case).

Andrew
  • 609
  • 7
  • 14