Application crash when close dialog



  • 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


  • Moderators

    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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.