Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To initialize data in Table you have to redefine data function, rowCount and clumnCount along with constructor of Model . suppose you have data int mydataarray[r][c] that is initialized in constructor. </p> <pre><code> TableModel::TableModel(int r,int c, double **initialdata) { R = r; C = c; mydataarray= initialdata; } QVariant TableModel::data(const QModelIndex &amp;index, int role) const { switch(role) { case Qt::DisplayRole: if(index.column()==0) { return QString::number(maydataarray[index.row()][index.column()]); } break; } </code></pre> <p>To set number of rows and column redefine </p> <pre><code>int TableModel::rowCount(const QModelIndex &amp;parent= QModelIndex()) const { return R;//R is number of initial rows } int TableModel::columnCount(const QModelIndex &amp;parent= QModelIndex()) const { return C;//C is number of initial columns } </code></pre> <p>in initialize function that actually you can use to modify but you have to insert rows and columns in model if they are exceeding the initial r and c </p> <pre><code> void TableModel::Initialize(double **a, int r, int c) { QModelIndex m = createIndex(0,0); if(r&gt;this-&gt;rowCount(m)||c&gt;this-&gt;columnCount(m)) { QMessageBox m1; m1.setText("Exciding r/c "+ QString::number(m.row())+QString::number(m.column())); m1.exec(); return;//add logic to insert exceeding rows and columns here before calling dataChange() function } mydataarray =a; QModelIndex n = createIndex(r-1,c-1); this-&gt;dataChanged(createIndex(0,0),n); } </code></pre> <p>refer <a href="http://doc.qt.digia.com/4.7/modelview.html#2-1-a-read-only-table" rel="nofollow">this</a> for further </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload