I've attached a code snippet to a C++ program I am working on Qt Creator. The goal of this snippet is to provide the user with a means to enter a custom temperature value and then save this value.
//custom temp
QLineEdit *addCustomTemp;
QLabel *customTemp = new QLabel("Custom temp");
addCustomTemp = new QLineEdit();
//QString tempVal = addCustomTemp->text();
// double tempValDouble = tempVal.toDouble();
//std::cout << "My temp" << tempValDouble;
QPushButton *submitButton = new QPushButton("Submit");
submitButton->setAutoDefault(false);
double tempValDouble;
auto handleCustomTemp = [&]() {
QString tempVal = addCustomTemp->text();
tempValDouble = tempVal.toDouble();
qDebug() << "Custom temp:" << tempValDouble;
};
connect(submitButton, &QPushButton::clicked, handleCustomTemp);
//widget for custom temp
layout->addWidget(customTemp, 1,2,1,1);
layout->addWidget(addCustomTemp, 1,3,1,1);
layout->addWidget(submitButton, 1,4,1,1);
//
The issue I currently have is that once the submitButton
button is clicked, the program crashes (or maybe just closes I'm not sure). I tried setting the default to false but that did not work.