title: How to read data using QSerialPort to write to a file using QFile?
body: <p>New to C++ and Qt, I'm trying to use a microcontroller to send a large set of data (made up of integers and commas) over serial to be put in a .csv file for use in Excel. My mainwindow.cpp code so far (where I've put all the action for testing purposes):</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;string&gt;
  #include &lt;QtSerialPort/QSerialPort&gt;
  #include &lt;QString&gt;
  #include &lt;QTextEdit&gt;
  #include &lt;QFile&gt;
  #include &lt;QTextStream&gt;
  
  QSerialPort *serial;
  using namespace std;
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      serial = new QSerialPort(this);
      serial-&gt;setPortName("/dev/cu.usbmodemfa131");
      serial-&gt;setBaudRate(QSerialPort::Baud9600);
      serial-&gt;setDataBits(QSerialPort::Data8);
      serial-&gt;setParity(QSerialPort::NoParity);
      serial-&gt;setStopBits(QSerialPort::OneStop);
      serial-&gt;setFlowControl(QSerialPort::NoFlowControl);
      serial-&gt;open(QIODevice::ReadWrite);
      connect(serial, SIGNAL(readyRead()), this, SLOT(serialReceived()));
  
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
      serial-&gt;close();
  }
  
  void MainWindow::serialReceived()
  {
      QString filename = "/Users/me/Documents/myFile/datacollecting.csv";
      QFile file(filename);
      QTextStream out(&amp;file);
      file.open(QIODevice::ReadWrite);
      QByteArray ba;
      ba = serial-&gt;readAll();
      out &lt;&lt; ba;
      file.close();
  }
  </code></pre>
  
  <p>The code however is giving me some issues. It does not work reliably at all and in the resultant file it only stores the last 10 or so (out of several thousand) characters. I have searched around but have not found a way to properly store large chunks of data over serial. Is there a better way to achieve what I'm trying to do above? New to this so any help would be greatly appreciated!</p>