QT使用另一个类的公共插槽

QT使用另一个类的公共插槽,qt,signals-slots,Qt,Signals Slots,我有一个类ArrayToolBar,它有一个公共成员commandBox和一个公共函数createArray() 下面是如何定义createArray() void ArrayToolBar::createArray(){ commandBox->setFocus(); connect(commandBox, SIGNAL(returnPressed()), this, SLOT(commandBox->SubmitCommand())); } SubmitComm

我有一个类
ArrayToolBar
,它有一个公共成员
commandBox
和一个公共函数
createArray()

下面是如何定义
createArray()

void ArrayToolBar::createArray(){
    commandBox->setFocus();
    connect(commandBox, SIGNAL(returnPressed()), this, SLOT(commandBox->SubmitCommand()));
}
SubmitCommand()是
CommandBox
类中的公共插槽

我的问题是,我得到了一个错误:没有这样的插槽存在。
这是因为我在
ArrayToolBar
中使用了其他类的插槽吗?有办法吗?

您可以对labmda表达式使用新的连接语法

Qt对此有很好的解释

最终代码如下所示:

connect(commandBox, &CommandBox::returnPressed,
        this, [=] () {commandBox->SubmitCommand();});

您可以使用前面提到的lambda表达式

但如果没有lambda,这应该可以满足您的需求:

connect(commandBox, SIGNAL(returnPressed()), commandBox, SLOT(SubmitCommand()))

连接(commandBox,&commandBox::returnPressed,this,[=](){commandBox->SubmitCommand();});谢谢,成功了!你能提供一个文档等的链接吗?在这里我可以阅读到这是如何工作的,特别是语法:[=]()。@SunitGautam我会写下答案的
connect(commandBox, SIGNAL(returnPressed()), commandBox, SLOT(SubmitCommand()))