Reputation: 6045
I have a class ArrayToolBar
which has a public member commandBox
and a public function createArray()
.
class ArrayToolBar : public QToolBar
{
Q_OBJECT
public:
explicit ArrayToolBar(const QString &title, QWidget *parent);
CommandBox* commandBox = new CommandBox();
void createArray();
Here is how createArray()
is defined
void ArrayToolBar::createArray(){
commandBox->setFocus();
connect(commandBox, SIGNAL(returnPressed()), this, SLOT(commandBox->SubmitCommand()));
}
SubmitCommand() is a public slot in
CommandBox
class.
My problem is that I am getting an error : No such slot exists.
Is this because I have used a slot of some other class in ArrayToolBar
? Is there a way around?
Upvotes: 0
Views: 61
Reputation: 1287
You can use lambda expressions like already mentioned.
But this should do what you want without lambda:
connect(commandBox, SIGNAL(returnPressed()), commandBox, SLOT(SubmitCommand()))
Upvotes: 0
Reputation: 971
You can use new connection syntax with labmda expressions.
Qt has a good aricle about it. https://wiki.qt.io/New_Signal_Slot_Syntax
And final code will looks like this:
connect(commandBox, &CommandBox::returnPressed,
this, [=] () {commandBox->SubmitCommand();});
Upvotes: 1