Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLineEdit crashing on recovering data

QLineEdit crashing on recovering data

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 332 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by Dummie1138
    #1

    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.

    Christian EhrlicherC 1 Reply Last reply
    0
    • Dummie1138D Dummie1138

      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.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dummie1138 said in QLineEdit crashing on recovering data:

      startTempInput

      And where do you initialize this variable (and the other QLineEdit pointers)?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Dummie1138D 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @Dummie1138 said in QLineEdit crashing on recovering data:

        startTempInput

        And where do you initialize this variable (and the other QLineEdit pointers)?

        Dummie1138D Offline
        Dummie1138D Offline
        Dummie1138
        wrote on last edited by
        #3

        @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 EhrlicherC JonBJ 2 Replies Last reply
        0
        • Dummie1138D Dummie1138

          @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 EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You still don't initialize the member variables, only local ones...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • Dummie1138D Dummie1138

            @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);
            }
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Dummie1138 Why not run under a debugger and then you will know for yourself why it's crashing?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved