title: Qt program error
body: <p>I made following program just for practice in Qt. My program crashes when I click an item in Listwidget so that the row number of that Item becomes an item in Listwidget_2. Here is the code. MainWindow.h is the same as generated by Qt IDE(no changes has been made, all the functions are predefined which have been used in .cpp file). Please also notify if i am making any memory leaks in the program because I am a beginner. </p>
  
  <p>Thanks for your help!</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  
  #include &lt;QMessageBox&gt;
  #include &lt;QTextStream&gt;
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
       ui-&gt;setupUi(this);
      noofitems=0;
      files.setFileName("E:/filev.txt");
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::on_actionDelete_Item_triggered()
  {
  
        qDeleteAll(ui-&gt;listWidget-&gt;selectedItems());
  }
  
  void MainWindow::on_okbutton_clicked()
  {
      QListWidgetItem *item=new QListWidgetItem;
  
      item-&gt;setText(ui-&gt;lineEdit-&gt;text());
      ui-&gt;listWidget-&gt;addItem(item);
      noofitems++;
  
      writefile();
  }
  
  void MainWindow::writefile()
  {
      QFile files("E:/legitfile.txt");
  
      if(files.exists())
      {
          if(!files.open(QFile::Append | QFile::Text))
          {
              QMessageBox::warning(this,"File Access!!!","The File containing data of the         Items and Comments can't be acessed",QMessageBox::Ok);
          }
      }else
          if(!files.open(QFile::WriteOnly | QFile::Text))
          {
              QMessageBox::warning(this,"File Access!!!","The File containing data of the     Items and Comments can't be acessed",QMessageBox::Ok);
          }
  
      QTextStream out(&amp;files);
      out&lt;&lt; noofitems&lt;&lt;',';
  
      files.flush();
      files.close();
  }
  </code></pre>
  
  <p><em><strong>THE PROGRAM CRASHES WHEN THE FOLLOWING FUNCTION IS CALLED</em></strong></p>
  
  <pre><code>void MainWindow::on_listWidget_itemClicked(QListWidgetItem *item)
  {
      QListWidgetItem *itm=new QListWidgetItem;
      itm-&gt;setText((char*)(ui-&gt;listWidget-&gt;currentRow()));
      ui-&gt;listWidget_2-&gt;addItem(itm);
  }
  </code></pre>