c++ - My simple QTableView code crashes -


i wrote simple code try , learn qtableview. when build project doesnt give errors when try run says:

c:\users\eren\documents\build-qtableviewuygulama-desktop_qt_5_8_0_msvc2015_64bit-debug\debug\qtableviewuygulama.exe exited code 255

or

the program has unexpectedly finished.

c:\users\eren\documents\build-qtableviewuygulama-desktop_qt_5_8_0_msvc2015_64bit-debug\debug\qtableviewuygulama.exe crashed.

i have knowledge c++ dont know qt. have no idea why keep getting error. here code

//class model(aracmodel.cpp) #include "aracmodel.h"  aracmodel::aracmodel(qobject* parent = 0) : qabstracttablemodel(parent) {  }  int aracmodel::rowcount(const qmodelindex &) const {  return 3;  } int aracmodel::columncount(const qmodelindex &) const {      return araclar.size(); } qvariant aracmodel::data(const qmodelindex &index, int role) const {      if(role != qt::displayrole && role != qt::editrole) return 0;      const arac& arac = araclar[index.row()];      switch(index.column()){          case 0 : return arac.id;         case 1 : return qstring::fromstdstring(arac.marka);         case 2 : return qstring::fromstdstring(arac.model);         default : return 0;     }     return qvariant(); }  qvariant aracmodel::headerdata(int section, qt::orientation orientation, int  role){      if(orientation != qt::horizontal || role != qt::displayrole) return 0;      switch(section){          case 0 : return "id";         case 1 : return "marka";         case 2 : return "model";         default : return 0;     }     return qvariant(); }   //class model (aracmodel.h) #ifndef aracmodel_h #define aracmodel_h  #include <qabstracttablemodel> #include "arac.h"  class arac;  class aracmodel : public qabstracttablemodel { public:     qlist<arac> araclar;      aracmodel(qobject*);      int rowcount(const qmodelindex&) const override;     int columncount(const qmodelindex&) const override;     qvariant data(const qmodelindex& index, int role) const override;     qvariant headerdata(int section, qt::orientation orientation, int role); };  #endif // aracmodel_h    //class header arac.h #ifndef arac_h #define arac_h  #include <string>  class arac { public:     int id;     std::string marka;     std::string model;      arac(int, std::string, std::string); };  #endif // arac_h  arac::arac(int i, std::string ma, std::string mo) : id(i), marka(ma), model(mo){} //this constructor in arac.cpp    //mainwindow.cpp (only copying parts i've changed) mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow) {     ui->setupui(this);     ui->tableview->setmodel(model); }     //mainwindow.hh(only copying parts i've changed class mainwindow : public qmainwindow {     q_object  public:     explicit mainwindow(qwidget *parent = 0);     aracmodel* model;     ~mainwindow();  private:     ui::mainwindow *ui; }; 

instantiate model pointer using :

model = new aracmodel(this);

before setting model tableview.

have @ simple example: http://www.thedazzlersinc.com/source/2012/06/04/qt-qtableview-example-short-and-quick/


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -