title: Using iomanip to format data output to a text file with Qt
body: <p>I am a student programmer using QT to develop and application for work. Currently I am developing the save functions in which data is taken from a table and saved to a file. Im running into some trouble when I try to write the data into columns. Not to confuse anyone; my problem is formatting text WHEN SAVING from the data table; not reading into it. So currently when data is saved from my Table it is saved into a file and looks like this: </p>
  
  <pre><code>0 0.048 300 101325 0 0
  10 0.048 300 101325 0 0
  </code></pre>
  
  <p>I need it to look like this</p>
  
  <pre><code>0  0.048 300 101325 0 0
  10 0.048 300 101325 0 0
  </code></pre>
  
  <p>During research I came across setw from the <a href="http://www.cprogramming.com/tutorial/iomanip.html" rel="nofollow">iomanip</a> library in c++ which sets a minimum amount of characters to fill data into and then uses the rest as padding. Sounds perfect right? Problem is I cant get it to work with anything besides cout; which isn't what I need it for. I need it to basically append spaces to my string prior to being written out. </p>
  
  <p>I also feel like Qt should probably have something to help me accomplish what I need here(alot easier). I just cant seem to find this member function after refencing <a href="http://qt-project.org/doc/qt-4.8/qstring.html#QString" rel="nofollow">QString documentation</a>, <a href="http://qt-project.org/doc/qt-4.8/QStringList.html" rel="nofollow">QStringList Doucmentation</a>, and most of all <a href="http://qt-project.org/doc/qt-4.8/qtextstream.html#setFieldWidth" rel="nofollow">QTextStream Documentation.</a></p>
  
  <p>Currently my save function looks like this:</p>
  
  <pre><code>QTextStream data(&amp;saveFileAsscf);
  QStringList tmpList;
  for (int x = 0; x&lt;ui-&gt;tableWidgetReaderTable-&gt;rowCount(); x++)
                  {
                      strList.clear();
                      for(int a = 0; a &lt; ui-&gt;tableWidgetReaderTable-&gt;columnCount(); a++)
                      {
                          strList &lt;&lt; ui-&gt;tableWidgetReaderTable-&gt;item(x,a)-&gt;text();
                      }
                      data &lt;&lt;strList.join(" ") &lt;&lt; "\n";
                  }
  </code></pre>
  
  <p>I am so sure that setFieldWidth is my answer from the <a href="http://qt-project.org/doc/qt-4.8/qtextstream.html#setFieldWidth" rel="nofollow">QTextStream Documentation.</a> but I cant get it to work right.
  Tried:</p>
  
  <pre><code>data.setFieldWidth(13) &lt;&lt; strList.join(" ") &lt;&lt; "\n";
  </code></pre>
  
  <p>I'm hoping that this is an easy answer for someone and I'm just running into some writers block but any help would be apperciated in accomplishing this. Thanks for reading my post and I appreciate any help contributed to bridge the gap here!</p>