std::string returned by saveOptionsDesLineEditBox->text().toStdString() is temporary. It goes out of scope at the end of the line and is destroyed along with its contents. Therefore, referring to the contained const char* returned by c_str() via desc , in the next line this behavior is undefined.
When you call
SDB::setDescription(saveOptionsDesLineEditBox->text().toStdString().c_str());
all in the same expression, temporary exists long enough so that setDescription can safely read and copy the string c.
I suggest something line by line
std::string desc = saveOptionsDesLineEditBox->text().toStdString(); SDB::setDescription(desc.c_str());
Strictly speaking, this will entail one copy more than necessary (or a move if you have c++11 ), but who really cares here. Making code easier to understand is a good thing in and of itself.
(Note this assumption without seeing any of the function signatures, but this is most likely a good option.)
source share