I'am stuck.
I have a class with two QList

Qt Code:
  1. class Formulas
  2. {
  3. public:
  4. Formulas();
  5. ~Formulas();
  6.  
  7. QString m_formula;
  8. QList<QString> m_variables;
  9. QList<QString> m_values;
  10. };
  11.  
  12. QDataStream & operator<< (QDataStream& stream, const Formulas& formula);
  13. QDataStream & operator>> (QDataStream& stream, Formulas& formula);
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. QDataStream & operator<< (QDataStream& stream, const Formulas& formula)
  2. {
  3. QString str;
  4. stream<<formula.m_formula;
  5. stream<<str.setNum(formula.m_variables.size());
  6.  
  7. for(int i=0;i<formula.m_variables.size();i++)
  8. {
  9. stream<<formula.m_values.at(i);
  10. stream<<formula.m_variables.at(i);
  11. }
  12.  
  13. return stream;
  14. }
  15.  
  16. //QList<Formulas> lista_formulas;
  17.  
  18. QDataStream & operator>> (QDataStream& stream, Formulas& formula)
  19. {
  20. QString str;
  21. int size;
  22. QString val;
  23. QString var;
  24. stream>>formula.m_formula;
  25. stream>>str;
  26. size=str.toInt();
  27.  
  28. for(int i=0;i<size;i++)
  29. {
  30. stream>>val;
  31. formula.m_values.append(val);
  32. stream>>var;
  33. formula.m_variables.append(var);
  34. }
  35.  
  36. return stream;
  37. }
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. formulas_dlg::formulas_dlg(QWidget *parent) :
  2. QDialog(parent),
  3. m_ui(new Ui::formulas_dlg)
  4. {
  5. m_ui->setupUi(this);
  6. .....
  7. QFile file("file.dat");
  8. file.open(QIODevice::ReadOnly);
  9. //QDataStream in(&file,&form_teste); // read the data serialized from the file
  10. in<<form_teste;
  11. file.close();
  12. // form_teste is of type Formulas defined in formulas_dlg class
  13. QMessageBox::about(this,"",form_teste.m_formula);
  14. ......
  15. }
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. void formulas_dlg::on_buttonBox_accepted()
  2. {
  3. QMessageBox::about(this,"","ok");// check if this function is called
  4.  
  5. form_teste.m_formula="xpto";//check if this data is written to file, and it's not file stays empty
  6.  
  7. QFile file("file.dat");
  8. file.open(QIODevice::WriteOnly);
  9. QDataStream out; // we will serialize the data into the file
  10. out << form_teste;
  11. file.close();
  12.  
  13. }
To copy to clipboard, switch view to plain text mode 

it compiles without erros, but the file is still empty after on_buttonBox_accepted is called.
Any ideas to solve this????????????????

Bta, this is the easy part. I really dont want to serialize the type "Formulas form_teste"
but the type "QList<Formulas> form_teste";
I am just doing it iin steps and trying to solve this error first.

Thank you