So, I tried this, but program goes out since I click "calculate"

Qt Code:
  1. #include "widget.h"
  2. #include <QAbstractItemModel>
  3.  
  4. Widget::Widget(QWidget *parent)
  5. : QWidget(parent)
  6. {
  7. this->setGeometry(30,30,800,750);
  8. rank = new QLineEdit("Enter the Rank", this);//rank->setGeometry(10,0,20,20);
  9. ok = new QPushButton("Ok", this); ok->setGeometry(150, 0,80,30);
  10. calculate = new QPushButton("calculate",this); calculate->setGeometry(250,0,80,30);
  11.  
  12.  
  13.  
  14. connect(ok,SIGNAL(clicked()),this,SLOT(ok_clicked()));
  15. connect(calculate,SIGNAL(clicked()),this,SLOT(calculate_clicked()));
  16. }
  17.  
  18. Widget::~Widget()
  19. {
  20.  
  21. }
  22.  
  23. void Widget::ok_clicked()
  24. {
  25.  
  26. rank_of_Matrix = rank->text().toDouble();
  27. tbl=new QTableWidget(rank_of_Matrix,rank_of_Matrix,this);
  28. tbl->setGeometry(20,50,770,250);
  29. tbl->show();
  30. }
  31.  
  32. void Widget::calculate_clicked()
  33. {
  34. tbl_2 = new QTableWidget(rank_of_Matrix,rank_of_Matrix,this);
  35.  
  36. tbl_2 ->setGeometry(20,350,770,250);
  37. Action_toArray();
  38. tbl_2 ->show();
  39. }
  40.  
  41. void Widget::Action_toArray()
  42. {
  43.  
  44. A= new float* [rank_of_Matrix];
  45. for(int i=0;i<rank_of_Matrix;i++){
  46. A[i]=new float [rank_of_Matrix];
  47. }
  48.  
  49. //read from Table 1 tbl
  50. for(int i=0;i<rank_of_Matrix;i++){
  51. for(int j=0;j<rank_of_Matrix;j++){
  52.  
  53. A[i][j] = tbl->item(i,j)-> data(Qt::DisplayRole).toFloat();
  54. }
  55. }
  56.  
  57. //operation with Array
  58. for(int i=0;i<rank_of_Matrix;i++){
  59. for(int j=0;j<rank_of_Matrix;j++){
  60. if(A[i][j]==2)
  61. {
  62. A[i][j]=0;
  63. }
  64. }
  65. }
  66.  
  67. //write to Table2 tbl_2
  68. QVariant tableData;
  69. for(int i=0;i<rank_of_Matrix;i++){
  70. for(int j=0;j<rank_of_Matrix;j++){
  71. tableData = A[i][j];
  72. tbl_2->item(i,j)->setData(Qt::EditRole,tableData);
  73. }
  74. }
  75. }
To copy to clipboard, switch view to plain text mode 

So, could you please tell me what is wrong and how I can fix it?