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. Application crash when close dialog
QtWS25 Last Chance

Application crash when close dialog

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.2k 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.
  • A Offline
    A Offline
    ayanamirei
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        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
        0

        • Login

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