如何调试失败的信号/插槽连接? [英] How to debug a failing signal/slot connection?
问题描述
我正在遵循茉莉花布兰切斯书第2章的书籍
I am following the Chapter 2 of Jasmin Blanchettes book
C++-GUI-Programming-with-Qt-4-1st-ed.pdf
尝试使用Qt的MS VS 2008设置对话框GoToCellDialog。
trying to setup the dialog GoToCellDialog using MS VS 2008 with Qt.
该示例编译,对话框显示,但无法在文本更改时输入处理程序方法on_lineEdit_textChanged()。
为了证明这一点,我将这行添加到插槽方法中:
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.
在.ui文件中,元素
<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.
我使用IDE生成代码,但首先它生成小写的gotocelldialog。
现在每个名字都是camelCase,代码编译。但是也许我错过了一些东西。
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.
推荐答案
我的程序中使用了一个功能来确保连接已经建立起来: p>
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.
这篇关于如何调试失败的信号/插槽连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!