title: Serialize a class with a Qlist of custom classes as member (using QDataStream)
body: <p>I'm trying to serialize class Lesson(my custom class[I removed some setters]), which includes a QList(Question is also my custom class). During test serialization I get a SIGSEGV(segmentation fault) when deserializing any object of QList inside the class Lesson.</p>
  
  <p>UPD1: I serialized QList* and now I changed it to QList, but SIGSEGV still appears.</p>
  
  <pre><code>class Lesson
  {
  
  public:
  Lesson();
  Lesson(QString, QString, QList&lt;Question&gt;);
  
  QString getName() const;
  QString getText() const;
  QList&lt;Question&gt;* getTest() const;
  
  friend QDataStream &amp;operator&lt;&lt;(QDataStream &amp;out, const Lesson &amp;l){
      out &lt;&lt; l.getName() &lt;&lt; l.getText();
      out &lt;&lt; l.getTest();
      return out;
  }
  
  friend QDataStream &amp;operator&gt;&gt;(QDataStream &amp;in, Lesson &amp;l){
      QString name;
      QString text;
      QList&lt;Question&gt; t;
      in &gt;&gt; name &gt;&gt; text &gt;&gt; t;
      l = Lesson(name, text, t);
      return in;
  }
  
  
  friend QDataStream &amp;operator&lt;&lt;(QDataStream &amp;out, const Lesson *&amp;l){
      out &lt;&lt; l-&gt;getName() &lt;&lt; l-&gt;getText();
      return out;
  }
  
  friend QDataStream &amp;operator&gt;&gt;(QDataStream &amp;in, Lesson *&amp;l){
      QString name;
      QString text;
      QList&lt;Question&gt; test;
      in &gt;&gt; name &gt;&gt; text;// &gt;&gt; test;
      l = new Lesson(name, text, test);
      return in;
  }
  
  
  private:
  QString text;
  QList &lt;Question&gt;* test_;
  QString name;
  
  
  
  };
  </code></pre>
  
  <p>//class Question starts here</p>
  
  <pre><code>class Question
  {
  
  public:
  explicit Question(QString, QList&lt;QString&gt;, int type, QList&lt;int&gt; ans);
  Question();
  
  friend QDataStream &amp;operator &lt;&lt;(QDataStream&amp; out, const Question &amp;q){
      out &lt;&lt; q.type &lt;&lt; q.questText &lt;&lt; q.variants &lt;&lt; q.answer;
      return out;
  }
  
  friend QDataStream &amp;operator &gt;&gt;(QDataStream&amp; in, Question &amp;q){
      int type;
      QString quesText;
      QList&lt;QString&gt; vars;
      QList&lt;int&gt;ans;
      in &gt;&gt; type &gt;&gt; q &gt;&gt; vars &gt;&gt; ans;
      q = Question(quesText, vars, type, ans);
      return in;
  }
  
  friend QDataStream &amp;operator &lt;&lt;(QDataStream&amp; out, const Question *&amp;q){
      //out.setByteOrder(QSysInfo::ByteOrder);
      out &lt;&lt; q-&gt;type &lt;&lt; q-&gt;questText &lt;&lt; q-&gt;variants &lt;&lt; q-&gt;answer;
      return out;
  }
  
  friend QDataStream &amp;operator &gt;&gt;(QDataStream&amp; in, Question *&amp;q){
      //in.setByteOrder(QSysInfo::ByteOrder);
      int type;
      QString quesText;
      QList&lt;QString&gt; vars;
      QList&lt;int&gt;ans;
      in &gt;&gt; type &gt;&gt; q &gt;&gt; vars &gt;&gt; ans;
      q = new Question(quesText, vars, type, ans);
      return in;
  }
  
  int gettype() const;
  QString getquestText() const;
  QList&lt;QString&gt; getvariants() const;
  QList&lt;int&gt; getanswer() const;
  
  signals:
  
  public slots:
  
  private:
  int type; // see constants.h
  QString questText;
  QList&lt;QString&gt; variants;
  QList&lt;int&gt; answer;
  
  
  };
  </code></pre>
  
  <p>// main.cpp where I test serialization</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  QApplication a(argc, argv);
  Core *c = new Core;
  MainWindow w;
  QObject::connect(&amp;w, SIGNAL(sendCheckUserValidityToCore(QString,QString)), c,      SLOT(checkUserValidity(QString,QString)));
  QObject::connect(&amp;w, SIGNAL(sendLessonToCore(Lesson*)), c, SLOT(saveLesson(Lesson*)));
  QObject::connect(&amp;w, SIGNAL(requestLessonByIdfromCore(QString)), c, SLOT(getLessonById(QString)));
  QObject::connect(c, SIGNAL(returnLessonById(Lesson*)), &amp;w, SIGNAL(returnLessonByIdfromCore(Lesson*)));
  QObject::connect(c, SIGNAL(entranceOff()), &amp;w, SLOT(entranceOff()));
  
  QFile tfile("lessons/tFile.stc");
  tfile.open(QIODevice::ReadWrite);
  QDataStream inout(&amp;tfile);
  QList&lt;Question&gt; qlistq;
  Question q;
  q.setQuestText("QWhy");
  qlistq.insert(0, q);
  
  Lesson lessont("hello", "welt", qlistq);
  Lesson lessonout;
  inout &lt;&lt; lessont;
  inout.device()-&gt;reset();
  inout &gt;&gt; lessonout;
  qDebug() &lt;&lt; lessonout.getName();
  
  
  return a.exec();
  }
  </code></pre>