Signals & Slots stopped working
-
Hi,
I have the following code which used to work:connect(ui->descr_TextEdit, &QTextEdit::textChanged, [this]() { description = getDescription (); });
Now it gives me the following error messages:
- 'description' is not captured
- the lambda has no capture default
- QString 'description' declared here.
How can I fix this?
Thank you. -
Hi @gabor53,
Does your class still have a
description
member? -
Can you show the actual compiler error output?
-
Can you show the actual compiler error output?
Hi @Paul-Colby
Here is the complete error message:C:\Programming\Projects\Folkfriends_1_0\additem.cpp:-1: In lambda function:
C:\Programming\Projects\Folkfriends_1_0\additem.cpp:254: error: 'description' is not captured
description = getDescription ();
^
C:\Programming\Projects\Folkfriends_1_0\additem.cpp:252: the lambda has no capture-default
connect(ui->descr_TextEdit, &QTextEdit::textChanged, this
^
C:\Programming\Projects\Folkfriends_1_0\additem.cpp:29: 'QString description' declared here
void Additem::Addcontent(QString name, QString newWhat, QString newMaterial, QString newColor, QString description, QString newmonth)
^ -
Hi @Paul-Colby
Here is the complete error message:C:\Programming\Projects\Folkfriends_1_0\additem.cpp:-1: In lambda function:
C:\Programming\Projects\Folkfriends_1_0\additem.cpp:254: error: 'description' is not captured
description = getDescription ();
^
C:\Programming\Projects\Folkfriends_1_0\additem.cpp:252: the lambda has no capture-default
connect(ui->descr_TextEdit, &QTextEdit::textChanged, this
^
C:\Programming\Projects\Folkfriends_1_0\additem.cpp:29: 'QString description' declared here
void Additem::Addcontent(QString name, QString newWhat, QString newMaterial, QString newColor, QString description, QString newmonth)
^@gabor53
Ifdescription
is a function parameter you must capture it explicitly:void Additem::Addcontent(QString name, QString newWhat, QString newMaterial, QString newColor, QString description, QString newmonth) { // ... connect(ui->descr_TextEdit, &QTextEdit::textChanged, [this, description]() { description = getDescription(); }); // ... }
But in any case such a capture is useless, because you can only do it by value.
-
Hi @gabor53,
Does your class still have a
description
member?@Paul-Colby said:
Does your class still have a
description
member?@gabor53 said:
Yes I have it.
void Additem::Addcontent(QString name, QString newWhat, QString newMaterial, QString newColor, QString description, QString newmonth)
That's not a class member.
Cheers.
-
@gabor53
Ifdescription
is a function parameter you must capture it explicitly:void Additem::Addcontent(QString name, QString newWhat, QString newMaterial, QString newColor, QString description, QString newmonth) { // ... connect(ui->descr_TextEdit, &QTextEdit::textChanged, [this, description]() { description = getDescription(); }); // ... }
But in any case such a capture is useless, because you can only do it by value.
@kshegunov
From the compiler output Additem::Addcontent is at line 29 while the lambda is at line 252 so I doubt it's nested. It's just description missing as a class member full stop -
@kshegunov
From the compiler output Additem::Addcontent is at line 29 while the lambda is at line 252 so I doubt it's nested. It's just description missing as a class member full stopso I doubt it's nested
At this point we can guess and bet.
It's just description missing as a class member full stop
Perhaps, or maybe the function is spanning 300 lines. The point is, without a more complete piece of the code we can't know for sure.
Do you mind sharing your class declaration and
Additem::Addcontent
function? -
@gabor53
Perhaps it compiles, but have you tested if it runs okay? Judging by the compile error and the solution, I'd be really surprised if you don't get a segfault. My previous request - to provide the whole function definition - stands. -
@gabor53
Perhaps it compiles, but have you tested if it runs okay? Judging by the compile error and the solution, I'd be really surprised if you don't get a segfault. My previous request - to provide the whole function definition - stands.Hi @kshegunov
Here is the full code:
additem.h
Addcontent function
Thank you for your help. -
Hi @kshegunov
Here is the full code:
additem.h
Addcontent function
Thank you for your help. -
- 'description' is not captured
said that in your lambda, 'description' has not been captured... then add it on the list of captured elements: [this, captured]
I red inside the answers that you may declare same name for function and variable... don't do that, it will generate problems for sure. - QString 'description' declared here
it is a clue for said that the answer of call this.getDescription() should be a QString (QString getDescription() const;)
so 'description' has to be a QString (i think in private area of this). because you are not pass it, it is an undeclared new object inside your lambda function.
so give a varaible name unik and pass the variable inside your lambda by the array list [....] should fix your problem.
- 'description' is not captured