QLineEdit crashing on recovering data
-
Hi. I have the following code.
code.c
void TestConfig::on_pushButton_New_clicked() { inputBox = new QDialog(this); //Set size of QDialog. QGridLayout *gridLayout = new QGridLayout(this); inputBox->setLayout(gridLayout); //QLabel QLabel *boxText = new QLabel(this); boxText->setText("Input new test presets:"); boxText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); boxText->setAlignment(Qt::AlignCenter); gridLayout->addWidget(boxText, 0, 0, 1, 2, Qt::AlignCenter); //Add a QLineEdit nameInput = new QLineEdit; gridLayout->addWidget(nameInput, 1, 1); //Add a QLineEdit startTempInput = new QLineEdit; gridLayout->addWidget(startTempInput, 2, 1); QLineEdit *expFlashptInput = new QLineEdit; gridLayout->addWidget(expFlashptInput, 3, 1); //Add a QDialogButtonBox QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this); gridLayout->addWidget(boxButton, 4, 0, 1, 2, Qt::AlignCenter); //Read information connect(boxButton, SIGNAL(accepted()), this, SLOT(setTestConfig())); connect(boxButton, SIGNAL(accepted()), inputBox, SLOT(accept())); } void TestConfig::setTestConfig(){ qDebug() << "In sTestC"; int startTemp = startTempInput->text().toInt(); int expFlashptTemp = expFlashptInput->text().toInt(); qDebug() << startTemp; qDebug() << endTemp; ConfigLibrarian librarian; ConfigurationSet config; config.name = nameInput->text(); config.serialNum = "desktop"; config.startTemp = startTempInput->text().toInt(); config.endTemp = 86; config.tempRate = 5.5; config.igniteFreq = 10; config.pressureThresh = 20; config.minTempAboveIni = 10; }code.h
namespace Ui { class TestConfig; } class TestConfig : public QDialog { Q_OBJECT private slots: void setTestConfig(); private: QDialog *inputBox; QLineEdit *nameInput, *startTempInput, *expFlashptInput; };I am crashing at this line:
int startTemp = startTempInput->text().toInt();
I am unsure why my function cannot return the values given at startTempInput, as it should still exist. Please let me know if more information is required. -
Hi. I have the following code.
code.c
void TestConfig::on_pushButton_New_clicked() { inputBox = new QDialog(this); //Set size of QDialog. QGridLayout *gridLayout = new QGridLayout(this); inputBox->setLayout(gridLayout); //QLabel QLabel *boxText = new QLabel(this); boxText->setText("Input new test presets:"); boxText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); boxText->setAlignment(Qt::AlignCenter); gridLayout->addWidget(boxText, 0, 0, 1, 2, Qt::AlignCenter); //Add a QLineEdit nameInput = new QLineEdit; gridLayout->addWidget(nameInput, 1, 1); //Add a QLineEdit startTempInput = new QLineEdit; gridLayout->addWidget(startTempInput, 2, 1); QLineEdit *expFlashptInput = new QLineEdit; gridLayout->addWidget(expFlashptInput, 3, 1); //Add a QDialogButtonBox QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this); gridLayout->addWidget(boxButton, 4, 0, 1, 2, Qt::AlignCenter); //Read information connect(boxButton, SIGNAL(accepted()), this, SLOT(setTestConfig())); connect(boxButton, SIGNAL(accepted()), inputBox, SLOT(accept())); } void TestConfig::setTestConfig(){ qDebug() << "In sTestC"; int startTemp = startTempInput->text().toInt(); int expFlashptTemp = expFlashptInput->text().toInt(); qDebug() << startTemp; qDebug() << endTemp; ConfigLibrarian librarian; ConfigurationSet config; config.name = nameInput->text(); config.serialNum = "desktop"; config.startTemp = startTempInput->text().toInt(); config.endTemp = 86; config.tempRate = 5.5; config.igniteFreq = 10; config.pressureThresh = 20; config.minTempAboveIni = 10; }code.h
namespace Ui { class TestConfig; } class TestConfig : public QDialog { Q_OBJECT private slots: void setTestConfig(); private: QDialog *inputBox; QLineEdit *nameInput, *startTempInput, *expFlashptInput; };I am crashing at this line:
int startTemp = startTempInput->text().toInt();
I am unsure why my function cannot return the values given at startTempInput, as it should still exist. Please let me know if more information is required.@Dummie1138 said in QLineEdit crashing on recovering data:
startTempInput
And where do you initialize this variable (and the other QLineEdit pointers)?
-
@Dummie1138 said in QLineEdit crashing on recovering data:
startTempInput
And where do you initialize this variable (and the other QLineEdit pointers)?
@Christian-Ehrlicher I have somehow failed to notice that in my attempt to reduce code fluff for this question I had deleted the critical elements. Thanks for bringing this up, I have re-edited the original code accordingly.
The full code.cpp:
void TestConfig::on_pushButton_New_clicked() { inputBox = new QDialog(this); //Set size of QDialog. inputBox->resize(450, 160); inputBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); inputBox->setStyleSheet("font: 20px; color: navy; border: none; outline: none;"); inputBox->setWindowFlag(Qt::WindowContextHelpButtonHint, false); QGridLayout *gridLayout = new QGridLayout(this); inputBox->setLayout(gridLayout); //QLabel QLabel *boxText = new QLabel(this); boxText->setText("Input new test presets:"); boxText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); boxText->setAlignment(Qt::AlignCenter); gridLayout->addWidget(boxText, 0, 0, 1, 2, Qt::AlignCenter); //Add a QLineEdit nameInput = new QLineEdit; gridLayout->addWidget(nameInput, 1, 1); //QLabel QLabel *nameText = new QLabel(this); nameText->setText("Name:"); nameText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); nameText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(nameText, 1, 0); //Add a QLineEdit startTempInput = new QLineEdit; gridLayout->addWidget(startTempInput, 2, 1); //QLabel QLabel *startTempText = new QLabel(this); startTempText->setText("Start temp:"); startTempText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); startTempText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(startTempText, 2, 0); //Add a QLineEdit QLineEdit *expFlashptInput = new QLineEdit; gridLayout->addWidget(expFlashptInput, 3, 1); //QLabel QLabel *expFlashptText = new QLabel(this); expFlashptText->setText("Expected flashpt:"); expFlashptText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); expFlashptText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(expFlashptText, 3, 0); //Add a QDialogButtonBox QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this); boxButton->setStyleSheet("QPushButton {border: 2px solid #8f8f91;border-radius: 9px;background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #f6f7fa, stop: 1 #dadbde);font: 25px;outline: none;}" "QPushButton:pressed {background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa) }"); boxButton->findChild<QPushButton *>()->setMinimumSize(80, 50); gridLayout->addWidget(boxButton, 4, 0, 1, 2, Qt::AlignCenter); //Read information connect(boxButton, SIGNAL(accepted()), this, SLOT(setTestConfig())); connect(boxButton, SIGNAL(accepted()), inputBox, SLOT(accept())); //Connect accepted to a seperate function too inputBox->exec(); qDebug() << "After InputBox"; } void TestConfig::setTestConfig(){ qDebug() << "In sTestC"; int startTemp = startTempInput->text().toInt(); ConfigLibrarian librarian; ConfigurationSet config; // config.name = nameInput->text(); config.serialNum = "desktop"; // config.startTemp = startTempInput->text().toInt(); config.endTemp = 86; config.tempRate = 5.5; // config.expectedFlashpt = expFlashptInput->text().toInt(); config.igniteFreq = 10; config.pressureThresh = 20; config.minTempAboveIni = 10; // librarian.addConfig(config); } -
@Christian-Ehrlicher I have somehow failed to notice that in my attempt to reduce code fluff for this question I had deleted the critical elements. Thanks for bringing this up, I have re-edited the original code accordingly.
The full code.cpp:
void TestConfig::on_pushButton_New_clicked() { inputBox = new QDialog(this); //Set size of QDialog. inputBox->resize(450, 160); inputBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); inputBox->setStyleSheet("font: 20px; color: navy; border: none; outline: none;"); inputBox->setWindowFlag(Qt::WindowContextHelpButtonHint, false); QGridLayout *gridLayout = new QGridLayout(this); inputBox->setLayout(gridLayout); //QLabel QLabel *boxText = new QLabel(this); boxText->setText("Input new test presets:"); boxText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); boxText->setAlignment(Qt::AlignCenter); gridLayout->addWidget(boxText, 0, 0, 1, 2, Qt::AlignCenter); //Add a QLineEdit nameInput = new QLineEdit; gridLayout->addWidget(nameInput, 1, 1); //QLabel QLabel *nameText = new QLabel(this); nameText->setText("Name:"); nameText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); nameText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(nameText, 1, 0); //Add a QLineEdit startTempInput = new QLineEdit; gridLayout->addWidget(startTempInput, 2, 1); //QLabel QLabel *startTempText = new QLabel(this); startTempText->setText("Start temp:"); startTempText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); startTempText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(startTempText, 2, 0); //Add a QLineEdit QLineEdit *expFlashptInput = new QLineEdit; gridLayout->addWidget(expFlashptInput, 3, 1); //QLabel QLabel *expFlashptText = new QLabel(this); expFlashptText->setText("Expected flashpt:"); expFlashptText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); expFlashptText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(expFlashptText, 3, 0); //Add a QDialogButtonBox QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this); boxButton->setStyleSheet("QPushButton {border: 2px solid #8f8f91;border-radius: 9px;background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #f6f7fa, stop: 1 #dadbde);font: 25px;outline: none;}" "QPushButton:pressed {background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa) }"); boxButton->findChild<QPushButton *>()->setMinimumSize(80, 50); gridLayout->addWidget(boxButton, 4, 0, 1, 2, Qt::AlignCenter); //Read information connect(boxButton, SIGNAL(accepted()), this, SLOT(setTestConfig())); connect(boxButton, SIGNAL(accepted()), inputBox, SLOT(accept())); //Connect accepted to a seperate function too inputBox->exec(); qDebug() << "After InputBox"; } void TestConfig::setTestConfig(){ qDebug() << "In sTestC"; int startTemp = startTempInput->text().toInt(); ConfigLibrarian librarian; ConfigurationSet config; // config.name = nameInput->text(); config.serialNum = "desktop"; // config.startTemp = startTempInput->text().toInt(); config.endTemp = 86; config.tempRate = 5.5; // config.expectedFlashpt = expFlashptInput->text().toInt(); config.igniteFreq = 10; config.pressureThresh = 20; config.minTempAboveIni = 10; // librarian.addConfig(config); }You still don't initialize the member variables, only local ones...
-
@Christian-Ehrlicher I have somehow failed to notice that in my attempt to reduce code fluff for this question I had deleted the critical elements. Thanks for bringing this up, I have re-edited the original code accordingly.
The full code.cpp:
void TestConfig::on_pushButton_New_clicked() { inputBox = new QDialog(this); //Set size of QDialog. inputBox->resize(450, 160); inputBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); inputBox->setStyleSheet("font: 20px; color: navy; border: none; outline: none;"); inputBox->setWindowFlag(Qt::WindowContextHelpButtonHint, false); QGridLayout *gridLayout = new QGridLayout(this); inputBox->setLayout(gridLayout); //QLabel QLabel *boxText = new QLabel(this); boxText->setText("Input new test presets:"); boxText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); boxText->setAlignment(Qt::AlignCenter); gridLayout->addWidget(boxText, 0, 0, 1, 2, Qt::AlignCenter); //Add a QLineEdit nameInput = new QLineEdit; gridLayout->addWidget(nameInput, 1, 1); //QLabel QLabel *nameText = new QLabel(this); nameText->setText("Name:"); nameText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); nameText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(nameText, 1, 0); //Add a QLineEdit startTempInput = new QLineEdit; gridLayout->addWidget(startTempInput, 2, 1); //QLabel QLabel *startTempText = new QLabel(this); startTempText->setText("Start temp:"); startTempText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); startTempText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(startTempText, 2, 0); //Add a QLineEdit QLineEdit *expFlashptInput = new QLineEdit; gridLayout->addWidget(expFlashptInput, 3, 1); //QLabel QLabel *expFlashptText = new QLabel(this); expFlashptText->setText("Expected flashpt:"); expFlashptText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); expFlashptText->setAlignment(Qt::AlignLeft); gridLayout->addWidget(expFlashptText, 3, 0); //Add a QDialogButtonBox QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this); boxButton->setStyleSheet("QPushButton {border: 2px solid #8f8f91;border-radius: 9px;background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #f6f7fa, stop: 1 #dadbde);font: 25px;outline: none;}" "QPushButton:pressed {background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa) }"); boxButton->findChild<QPushButton *>()->setMinimumSize(80, 50); gridLayout->addWidget(boxButton, 4, 0, 1, 2, Qt::AlignCenter); //Read information connect(boxButton, SIGNAL(accepted()), this, SLOT(setTestConfig())); connect(boxButton, SIGNAL(accepted()), inputBox, SLOT(accept())); //Connect accepted to a seperate function too inputBox->exec(); qDebug() << "After InputBox"; } void TestConfig::setTestConfig(){ qDebug() << "In sTestC"; int startTemp = startTempInput->text().toInt(); ConfigLibrarian librarian; ConfigurationSet config; // config.name = nameInput->text(); config.serialNum = "desktop"; // config.startTemp = startTempInput->text().toInt(); config.endTemp = 86; config.tempRate = 5.5; // config.expectedFlashpt = expFlashptInput->text().toInt(); config.igniteFreq = 10; config.pressureThresh = 20; config.minTempAboveIni = 10; // librarian.addConfig(config); }@Dummie1138 Why not run under a debugger and then you will know for yourself why it's crashing?