Ralf K.
Ralf K.

Reputation: 125

How to debug a failing signal/slot connection?

I am following the Chapter 2 of Jasmin Blanchettes book

C++-GUI-Programming-with-Qt-4-1st-ed.pdf

trying to setup the dialog GoToCellDialog using MS VS 2008 with Qt.

The example compiles, the dialog appears, but it fails to enter the handler method on_lineEdit_textChanged() on text changes. To prove it, i added this line to the slot method:

label->setText(tr("Changed :"));

to force a visual change in the label.

In the .ui file the element

<connections/>

is empty. I don't know why.

I decided to add this line to the constructor:

connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(on_lineEdit_textChanged()));

But it doesn't change anything.

I used the IDE to generate the code, but first it generated gotocelldialog in lowercase. Now every name is camelCase and the code compiles. But perhaps I missed something.

Upvotes: 1

Views: 2122

Answers (1)

UmNyobe
UmNyobe

Reputation: 22890

There is a function I use in my program to make sure connections are well established :

 inline void CHECKED_CONNECT( const QObject * sender, const char * signal,
             const QObject * receiver,  const char * method,
             Qt::ConnectionType type = Qt::AutoConnection )
{
  if(!QObject::connect(sender, signal, receiver, method, type))
   qt_assert_x(Q_FUNC_INFO, "CHECKED_CONNECT failed", __FILE__, __LINE__);
}

This is a wrapper on the usual connect which throws an assertion error and halts the program as soon as a connection fails. Well it will be useful only for the connections you make using the source code.

Upvotes: 4

Related Questions