title: Qt read specific columns of tab delimited text file
body: <p>I'm working on a program that reads a text file of tab delimited doubles and sums up each column, effectively calculating the integral of each column.</p>
  
  <p>What I want to be able to do is choose a specific column to sum up rather than sum all the columns.</p>
  
  <p>The code I've already got working for the integral of all columns:</p>
  
  <pre><code>void MainWindow::on_pushButton_clicked()
  {
  
  
      data::SingleLineData.resize(512);
      QString test;
      QString inputfile = QFileDialog::getOpenFileName(
                  this,
                  tr("Open File"),
                  "/Users",
                  "All files (*.*)"
                  );
  
      if(inputfile != ""){
      QFile file(inputfile);
  
  
      if(!file.open(QFile::ReadOnly)){
         }
      QTextStream in(&amp;file);
  
  
          double buffer;
  
          while(!file.atEnd()){
              in.readLine();
              for(int i=0; i&lt;512; i++){
                  in &gt;&gt; buffer;
                  data::SingleLineData[i]+=buffer;
              }
          }
  
      }
          qDebug() &lt;&lt; data::SingleLineData;
  // ************* file output **************************************************
  
          QString filename = QFileDialog::getSaveFileName(
                      this,
                      tr("Save File"),
                      "/Users",
                      "Text files (*.txt)"
                      );
          QFile fileout(filename);
          if (fileout.open(QFile::ReadWrite | QFile::Truncate)){
           QTextStream out(&amp;fileout);
           for (QVector&lt;double&gt;::iterator iter = data::SingleLineData.begin(); iter != data::SingleLineData.end(); iter++){
               out &lt;&lt; *iter &lt;&lt;", ";
           }
           fileout.close();
          }
  }
  </code></pre>
  
  <p>And here is my attempt at choosing out an individual column using an integer input into a spin box:</p>
  
  <pre><code>void MainWindow::on_pushButton_2_clicked()
  {
      QString inputfile = QFileDialog::getOpenFileName(
                  this,
                  tr("Open File"),
                  "/Users",
                  "All files (*.*)"
                  );
      QVector&lt;double&gt; SingleChannel;
  
      if (inputfile != ""){
          QFile file(inputfile);
  
          if (!file.open(QIODevice::ReadOnly)){
          }
          QTextStream in(&amp;file);
          SingleChannel.resize(1);
          double buffer;
          int channelnumber = ui-&gt;spinBox-&gt;value();
          while(!file.atEnd()){
              in.readLine();
              for (int i = 0; i &lt; 512; i++){
                  in &gt;&gt; buffer;
                  if (i == channelnumber){
                      SingleChannel.push_back(buffer);
                  }
                  data::SingleLineData[i]+=buffer;
              }
          }
      }
      qDebug() &lt;&lt; SingleChannel;
  }
  </code></pre>
  
  <p>I get the following error though:</p>
  
  <pre><code>ASSERT failure in QVector&lt;T&gt;::operator[]: "index out of range", file /Users/mduncan/Qt/5.3/clang_64/lib/QtCore.framework/Headers/qvector.h, line 385
  The program has unexpectedly finished.
  </code></pre>
  
  <p>Anyone have any ideas?</p>
  
  <p>Thanks :)</p>