Hi,

i'm making a QTreeWidget that uses an object that inherits from QTreeWidgetItem.

the code is:
Object.h
Qt Code:
  1. #pragma once
  2.  
  3. #include <QPixmap>
  4. #include <QDir>
  5. #include <QFile>
  6. #include <QString>
  7. #include <QTreeWidgetItem>
  8.  
  9. #include "Resources.h"
  10.  
  11. class Object:public QTreeWidgetItem{
  12. public:
  13. Object(QString file="",QString fileInfo="");
  14. void init();
  15.  
  16. bool isObject(){return (m_pixmap!=NULL);};
  17. void setName(QString newValue);
  18. void setPixmap(QString file=RES_FOLDER_22x22);
  19. private:
  20. QPixmap *m_pixmap;
  21. QString m_name;
  22. QString m_file;
  23. QString m_fileInfo;
  24. };
To copy to clipboard, switch view to plain text mode 

Object.cpp
Qt Code:
  1. #include "Object.h"
  2.  
  3. Object::Object(QString file,QString fileInfo):m_file(file),m_fileInfo(fileInfo){
  4. m_pixmap=NULL;
  5. init();
  6. }
  7.  
  8. void Object::init(){
  9. if(QFileInfo(m_file).isDir()){
  10. QDir dir(m_file);
  11. setName(dir.dirName());
  12. setPixmap();
  13. foreach(QString entry, dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot)){
  14. Object *newObject;
  15. addChild(newObject);
  16. newObject=new Object(m_file+"/"+entry);
  17. }
  18. }
  19. else{
  20.  
  21. }
  22. }
  23.  
  24. void Object::setName(QString newValue){
  25. m_name=newValue;
  26. setText(0,newValue);
  27. }
  28.  
  29. void Object::setPixmap(QString file){
  30. if(QFile(file).exists()){
  31. if(m_pixmap) delete m_pixmap;
  32. m_pixmap=new QPixmap(file);
  33. setIcon(0,QIcon(file));
  34. }
  35. }
To copy to clipboard, switch view to plain text mode 
and the function that fills the QTreeWidget

Qt Code:
  1. void Objects::refreshFiles(){
  2. QString objectsPath=OBJECTS_PATH;
  3. QDir dirInfo(objectsPath);
  4. if(dirInfo.exists()){
  5. foreach(QString entry, dirInfo.entryList(QDir::Dirs|QDir::NoDotAndDotDot)){
  6. Object *item=new Object(dirInfo.absolutePath()+"/"+entry);
  7. treeObjects->addTopLevelItem(item);
  8. }
  9. }
  10. }
To copy to clipboard, switch view to plain text mode 
for the TopLevelItems it works fine, but in subitems it uses the first top level item again.

Any ideas. Thanks