{
connect(
ui.btnHelp, SIGNAL(clicked()), this, SLOT(OnBtnHelp())
);
connect(
ui.btnHelp, SIGNAL(toggled(bool)), this, SLOT(OnBtnHelpChanged(bool))
);
ui.setupUi(this);
}
上面这段代码报错如下:
QObject::connect: Cannot connect (null)::clicked() to Test5_4::OnBtnHelp()
QObject::connect: Cannot connect (null)::toggled(bool) to Test5_4::OnBtnHelpChanged(bool)
这是ui没有被提前初始化的原因,把最后一段代码前置就可以了,原因是:(quote自http://blog.csdn.net/oowgsoo/article/details/1529411#comments)
即编译器未能识别到信号发送者,sender为零时,报错NULL。
// 不允许空输入
if (sender == 0 || receiver == 0 || signal == 0 || method == 0) {
#ifndef QT_NO_DEBUG
qWarning("Object::connect: Cannot connect %s::%s to %s::%s",
sender ? sender->metaObject()->className() : "(null)",
signal ? signal+1 : "(null)",
receiver ? receiver->metaObject()->className() : "(null)",
method ? method+1 : "(null)");
#endif
return false;
}
发送和接收者定义重叠,也会保类似错误,详见:
http://stackoverflow.com/questions/8493506/qobjectconnect-cannot-connect-null