我有一个 ArrayToolBar
类,它有一个公共成员 commandBox
和一个公共函数 createArray()
.
class ArrayToolBar : public QToolBar
{
Q_OBJECT
public:
explicit ArrayToolBar(const QString &title, QWidget *parent);
CommandBox* commandBox = new CommandBox();
void createArray();
以下是 createArray()
的定义方式
void ArrayToolBar::createArray(){
commandBox->setFocus();
connect(commandBox, SIGNAL(returnPressed()), this, SLOT(commandBox->SubmitCommand()));
}
SubmitCommand()是CommandBox类中的公共槽 .
我的问题是我收到一个错误:没有这样的插槽存在 . 这是因为我在 ArrayToolBar
中使用了一些其他类的插槽吗?有办法吗?
2 回答
您可以使用已经提到的lambda表达式 .
但这应该做你想要的没有lambda:
您可以将新连接语法与labmda表达式一起使用 .
Qt有一个很好的论点 . https://wiki.qt.io/New_Signal_Slot_Syntax
最终代码如下所示: