Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Application crash when close dialog

    General and Desktop
    3
    3
    977
    Loading More Posts
    • 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.
    • A
      ayanamirei last edited by

      All code here

      header file:

      @namespace Ui {
      class DlgSetupOther;
      }

      class DlgSetupOther : public QDialog
      {
      Q_OBJECT

      public:
      explicit DlgSetupOther(QWidget *parent = 0);
      ~DlgSetupOther();

      private:
      Ui::DlgSetupOther *ui;

      static const int maxEnvVariableRecno=11;
      QLineEdit* leEnvVariable[maxEnvVariableRecno+1];
      

      };
      @
      cpp file:

      @DlgSetupOther::DlgSetupOther(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::DlgSetupOther)
      {
      ui->setupUi(this);

      leEnvVariable[2]=ui->lineEdit_ev_2;
      leEnvVariable[3]=ui->lineEdit_ev_3;
      leEnvVariable[4]=ui->lineEdit_ev_4;
      leEnvVariable[5]=ui->lineEdit_ev_5;
      leEnvVariable[6]=ui->lineEdit_ev_6;
      leEnvVariable[7]=ui->lineEdit_ev_7;
      leEnvVariable[8]=ui->lineEdit_ev_8;
      leEnvVariable[9]=ui->lineEdit_ev_9;
      leEnvVariable[10]=ui->lineEdit_ev_10;
      leEnvVariable[11]=ui->lineEdit_ev_11;
      

      }

      DlgSetupOther::~DlgSetupOther()
      {
      delete ui;
      }
      @

      I push several lineedit pointers into leEnvVariable array in order to facilitate loop process later. Now when I close dialog, app segment fails. If I remove leEnvVariable and its value assignment, everything is ok.

      What is wrong in my code? advise plz

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        It would be much easier and less error-prone to use QList or QVector.

        Please debug your code and see where exactly does it fail. I don't see anything wrong in the attached code.

        If you delete your dialog after it is closed, then you are also deleting the ui object, and thus all lineEdit pointers become invalid. If you try to use them later: you have a crash.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • dheerendra
          dheerendra Qt Champions 2022 last edited by

          There is not problem with the above code snippet. Looks you must be deleting or doing something else with lineEdit pointer variable. Your complete code snippet would help. Your main also would help. Absolutely no issue with only above code snippet.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply Reply Quote 0
          • First post
            Last post