Simple program crash when closing a dialog



  • I created a simple dialog to change the user's passwords. It has a table model view and two fields one showing the user name and another the current password. The problem is that when i close the dialog, either by the X on top or the cancel button, the program crash. I created the dialog using the wizard. I tried to run the debugger but only shows the assembler code with a message box saying that received a signal with segmentation fault. Here is the dialog code:
    cpp.file:

    #include "userpasswd.h"
    #include "ui_userpasswd.h"
    
    UserPasswd::UserPasswd(dataStruct *w, QWidget *parent) : QDialog(parent), ui(new Ui::UserPasswd)
    {
      ui->setupUi(this);
      workData=w;
      fillUserModel();
    }
    
    UserPasswd::~UserPasswd()
    {
      delete ui;
    }
    
    void UserPasswd::fillUserModel()
    {
      model=new QSqlTableModel(this);
      model->setTable("user");
      model->setHeaderData(0,Qt::Horizontal,"ID");
      model->setHeaderData(1,Qt::Horizontal,"User");
      model->setHeaderData(3,Qt::Horizontal,"Active");
      model->setHeaderData(4,Qt::Horizontal,"Name");
      model->setHeaderData(5,Qt::Horizontal,"Last");
      model->select();
    
      ui->userTable->setModel(model);
      ui->userTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
      ui->userTable->resizeColumnsToContents();
      ui->userTable->resizeRowsToContents();
      ui->userTable->setSortingEnabled(true);
    
      ui->userTable->show();
    }
    
    void UserPasswd::on_cancel_clicked()
    {
      this->reject();
    }
    
    void UserPasswd::on_save_clicked()
    {
      QSqlQuery query;
      query.prepare("update user user_passwd=:user_passwd where user_id=:user_id");
      query.bindValue(":user_passwd",ui->userPasswd->text());
      query.bindValue(":user_id",ui->userNumber->value());
      query.exec();
      QMessageBox::warning(this,"User Password","User Password changed..");
      ui->userPasswd->clear();
      ui->userNumber->clear();
      model->select();
    }
    
    void UserPasswd::on_userTable_clicked(const QModelIndex &index)
    {
      curIndex=index;
      ui->userNumber->setValue(model->record(curIndex.row()).value(0).toInt());
      ui->userPasswd->setText(model->record(curIndex.row()).value(2).toString());
    }
    

    h file just in case:

    #ifndef USERPASSWD_H
    #define USERPASSWD_H
    
    #include <QDialog>
    #include <QSqlQuery>
    #include <QSqlTableModel>
    #include <QSqlRecord>
    #include <QMessageBox>
    
    #include "common.h"
    
    namespace Ui {
      class UserPasswd;
    }
    
    class UserPasswd : public QDialog
    {
      Q_OBJECT
    
    public:
      explicit UserPasswd(dataStruct *w, QWidget *parent = 0);
      ~UserPasswd();
      void fillUserModel(void);
    
    
    private slots:
      void on_cancel_clicked();
      void on_save_clicked();
    
      void on_userTable_clicked(const QModelIndex &index);
    
    private:
      Ui::UserPasswd *ui;
      QSqlTableModel *model;
      QModelIndex curIndex;
    
      dataStruct *workData;
    };
    
    #endif // USERPASSWD_H
    

  • Qt Champions 2017

    Hi
    Nothing look wrong.

    Can you show how you call it ?


  • Lifetime Qt Champion

    Hi,

    To add to @mrjj, if you only get assembler when running the debugger, then you are likely trying to debug a release version of your application. Is this the case ?


Log in to reply
 

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