Hi all.
i have a non-really-qt related newbie problem that you surely can solve easily.

i have a class 'Model' which holds some members. one of thos is a QList.
this is the code for that class:

Header:
Qt Code:
  1. #ifndef MODEL_H
  2. #define MODEL_H
  3.  
  4. #include <QList>
  5.  
  6. class Model
  7. {
  8. public:
  9. Model();
  10. QList<QString> list() const;
  11.  
  12. private:
  13.  
  14. QList<QString> m_list;
  15. };
  16.  
  17. #endif // MODEL_H
To copy to clipboard, switch view to plain text mode 

cpp
Qt Code:
  1. #include "model.h"
  2. #include <QString>
  3.  
  4. Model::Model()
  5. {
  6. m_list.append(QString("item1"));
  7. m_list.append(QString("item2"));
  8. }
  9.  
  10. QList<QString> Model::list() const
  11. {
  12. return m_list;
  13. }
To copy to clipboard, switch view to plain text mode 

when i execute this snippet of code:

Qt Code:
  1. Model m;
  2.  
  3. qDebug() << "Before clear()";
  4. for(int i=0;i<m.list().count();i++)
  5. {
  6. qDebug() << m.list().at(i);
  7. }
  8.  
  9. m.list().clear();
  10.  
  11. qDebug() << "After clear()";
  12. for(int i=0;i<m.list().count();i++)
  13. {
  14. qDebug() << m.list().at(i);
  15. }
To copy to clipboard, switch view to plain text mode 

i get this output:

Qt Code:
  1. "Before clear()"
  2. "item1"
  3. "item2"
  4. "After clear()"
  5. "item1"
  6. "item2"
To copy to clipboard, switch view to plain text mode 

i think that the problem is the fact that calling m.list() returns me a copy of the QList instead of a reference to it.
i think that one way to solve this is returning a pointer to the QList instead, but i'm wondering if there is another way to do this avoiding pointers.

sorry for the long post and thanks if you read since here