Signals and Slots
-
Hi,
I have the following code:connect(ui->notes_TextEdit, &QTextEdit::textChanged, [&]() { notes = getNotes (); });
Get notes is defined as
QString getNotes();
in .h.
The function:QString Additem::getNotes() { notes = ui->notes_TextEdit->toPlainText (); notes = notes.simplified (); return notes; }
Whenever the program execution reaches connect.... the program crashes. The same code works with other variables elsewhere. What is wrong with this one?
Thank you. -
@hskoglund
Thanks but it generated another error message:C:\Programming\Projects\Folkfriends_1_0\additem.cpp:340: error: expected identifier before ']' token
connect(ui->notes_TextEdit, &QTextEdit::textChanged, this,&
^
C:\Programming\Projects\Folkfriends_1_0\additem.cpp:342: error: 'notes' is not captured
notes = getNotes ();
^
and the code:connect(ui->notes_TextEdit, &QTextEdit::textChanged, [this,&]() { notes = getNotes (); });
-
@hskoglund
Now we went further:
I received the following error message:It happens in a file called atomic_base.h (frankly, I have no idea what that is) .
Here is the file:
atomic_base.h.
The error occurs at line 396. -
Hi, I think it's complaining that you're reusing the same variable notes in both the lambda and in getNotes(), try change getNodes something like this:
QString Additem::getNotes() { QString notesTemp = ui->notes_TextEdit->toPlainText (); notesTemp = notesTemp.simplified (); return notesTemp; }
-
Ok, I think it's colliding with same other variable notes that you have in your Additem class, most likely a function argument, for example in the function that has that connect statement.
Anyway, suggest to refactor it to same other name, not notes, then you also should be able to use [this], something like this:
connect(ui->notes_TextEdit, &QTextEdit::textChanged, [this]() { anythingButNotes = getNotes (); });