c++ - Empty lines in QStandardItemModel with custom data -


the header ok, have 3 empty lines.

the method fileconfig::data never called!
have idea why?

model= new mymodel;  model->setheaderdata(0, qt::horizontal, tr("title")); model->setheaderdata(1, qt::horizontal, tr("direcory")); model->setheaderdata(2, qt::horizontal, tr("date"));  model->invisiblerootitem()->setchild(0, new fileconfig("/home/user/dir/riri.conf")); model->invisiblerootitem()->setchild(1, new fileconfig("/home/user/dir/fifi.conf")); model->invisiblerootitem()->setchild(2, new fileconfig("/home/user/dir/loulou.conf"));  proxy= new qsortfilterproxymodel(this); proxy->setsourcemodel(model);  view= new qtreeview; view->setmodel(proxy); 

mymodel inherite qstandarditemmodel, empty moment.
custom class:

class fileconfig : public qstandarditem {     public:         std::string getfilename() const;         std::string getfiledirectory() const;         std::string getdate() const;          fileconfig(const char *fileconfig);          virtual qstandarditem *clone() const;         virtual qvariant data(const qmodelindex &index, int role= qt::displayrole) const;      private:         boost::filesystem::path file; };  fileconfig::fileconfig(const char *fileconfig) : qstandarditem() {     file= boost::filesystem::path(fileconfig); }  qvariant fileconfig::data(const qmodelindex &index, int role) const {     if(role == qt::displayrole)         switch(index.column()) {             case 0: return getfilename().c_str();             case 1: return getfiledirectory().c_str();             case 2: return getdate().c_str(); }     return qvariant(); } 

try using appendrow instead of setchild when add new items model. example:

model->invisiblerootitem()->appendrow(new fileconfig(/*path*/)); 

edit: need q_object macro in class definition of fileconfig, otherwise signals , slots not work. remember re-run qmake after add macro.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -