title: Saving the state of a Qt application to a file
body: <p>I am somewhat of a newbie and I can't get the saving and loading to work.
  The program has some radio buttons and spinboxes, I want to be able to save those positions and values to a file, and be able to open it again later. 
  Here is the saving:</p>
  
  <pre><code>void MainWindow::on_saveButton_clicked()
  {
   QString fileName = QFileDialog::getSaveFileName(this,
       tr("Salvesta Projekt"), "",
       tr("Latid Pindalaks (*.lp);;All Files (*)"));
  
   if (fileName.isEmpty())
       return;
   else {
       QFile file(fileName);
       if (!file.open(QIODevice::WriteOnly)) {
           QMessageBox::information(this, tr("Unable to open file"),
               file.errorString());
           return;
       }
       QDataStream out(&amp;file);
       out.setVersion(QDataStream::Qt_4_8);
  
       QByteArray MyArray = MainWindow::saveState();
  
       out &lt;&lt; (MyArray);
        }
   }
  </code></pre>
  
  <p>And here is the Loading</p>
  
  <pre><code>void MainWindow::on_loadButton_clicked()
  {
   QString fileName = QFileDialog::getOpenFileName(this,
       tr("Ava Projekt"), "",
       tr("Latid Pindalaks (*.lp);;All Files (*)"));
  
   if (fileName.isEmpty())
       return;
   else {
  
       QFile file(fileName);
  
       if (!file.open(QIODevice::ReadOnly)) {
           QMessageBox::information(this, tr("Pole võimalik faili laadida"),
               file.errorString());
           return;
       }
  
       QDataStream in(&amp;file);
       in.setVersion(QDataStream::Qt_4_8);
  
       in &gt;&gt; (MyArray);
  
       MainWindow::restoreState(MyArray);
   }
  }
  </code></pre>
  
  <p>I know i'm doing something very wrong, so a good example would be very appreciated.</p>