title: How to add custom object to TableView in Qt Creator in C++?
body: <p>I wrote a simple tableview in Qt Creator with default data. Can anyone help me how to set a custom data object into the columns?</p>
  
  <p>And also I will be inserting and deleting the data continuously into the table. Is there anyway to do this without specifying the row number and column number? </p>
  
  <p>I am very much new to Qt. All the examples given are showing adding of the data to respective row and respective column. I wrote this Tableview in JAVAFx and it is very easy to store and delete data from the table. </p>
  
  <p><strong>My Main Code:</strong></p>
  
  <pre><code>#include "mainwindow.h" 
  #include "mydata.h"
  #include &lt;QApplication&gt;
  #include &lt;QVariant&gt;
  #include &lt;QTableView&gt;
  #include &lt;QTreeView&gt;
  
  int main(int argc, char *argv[])
  
  {
      QApplication a(argc, argv);
      mydata *data=new mydata;
      QVariant variant;
      variant.setValue(data);
      QStandardItemModel *model = new QStandardItemModel();
      QStandardItem *parentItem = model-&gt;invisibleRootItem();
      QStandardItem *item = new QStandardItem();
      model-&gt;setColumnCount(5);
      model-&gt;setRowCount(5);
      model-&gt;setData(model-&gt;index(0, 0), "data1");
      model-&gt;setData(model-&gt;index(0, 1), "data2");
      model-&gt;setData(model-&gt;index(0, 2), "data3");
      model-&gt;setData(model-&gt;index(0, 3), "data4");
      model-&gt;setData(model-&gt;index(0, 4), "data5");
      QTreeView *treeView = new QTreeView();
      QTableView *tableView = new QTableView();
      tableView-&gt;setModel(model);
      item-&gt;setText(QString("some data"));
      tableView-&gt;show();
      return a.exec();
  }
  </code></pre>
  
  <p><strong>My custom Object:</strong></p>
  
  <pre><code>#include "mydata.h" 
  #include &lt;string&gt;
  
  mydata::mydata()
  
  {
      Account="finsoldts5";
      Exchange="CME";
      Orderstatus="Filled";
      Clorid="CME";
  }
  </code></pre>
  
  <p>I want to append the "mydata" class object to the table like:
  Column 1 contains Account and column 2 contains Exchange and column 3 contains Orderstatus and last column contains Clordid.</p>
  
  <p>How can I do this dynamically every time I get these details. That is I want to add the object to the Table last row every time I get new data. A full example is appreciable as I am very new to CPP and also to Qt.</p>