i am implementing a custom model using a System.Data.DataTable, but get<br>this error:<br><br clear="all">Fatal error: C# instance has been wrongly GC'd for virtual 0xa3fa3f8->QAbstractItemModel::rowCount(const QModelIndex&) const call.<br>
<br>this is the code:<br><br>using System;<br>using Qyoto;<br>namespace qtnet<br>{<br> <br> public class TableModelSample<br> {<br> <br> private QTableView view;<br> private TableModel model;<br>
public TableModelSample()<br> {<br> System.Data.DataTable table = new System.Data.DataTable();<br> table.Columns.Add("Name");<br> table.Columns.Add("Age");<br>
<br> for(int i=0 ; i<1000; i++){<br> System.Data.DataRowView drv = table.DefaultView.AddNew();<br> drv.BeginEdit();<br> drv["Name"]=String.Format("name for {0} is = ", i );<br>
drv["Age"] =String.Format("age for {0} is = ", i );<br> drv.EndEdit();<br> }<br> <br> model= new TableModel(table.DefaultView);<br> view = new QTableView();<br>
view.SetModel(model);<br> view.WindowTitle = "Simple Table Model";<br> view.Show();<br> }<br><br> public static int Main(string[] args){<br> new QApplication(args);<br>
new TableModelSample();<br> return QApplication.Exec();<br> }<br> <br> }<br> <br> public class TableModel:QAbstractTableModel{<br> System.Data.DataView model;<br> <br>
public TableModel(System.Data.DataView model, QObject parent) : base(parent){<br> this.model=model;<br> }<br> <br> public TableModel(System.Data.DataView model):this(model,(QObject)null){<br>
<br> }<br> <br> <br> public override int RowCount (QModelIndex parent)<br> { <br> return model.Count; <br> }<br> <br> public override int ColumnCount(QModelIndex parent){<br>
return this.model.Table.Columns.Count;<br> }<br><br> public override QModelIndex Parent(QModelIndex index) {<br> return new QModelIndex(); <br> }<br> <br> public override QVariant Data(QModelIndex index, int role) {<br>
if (!index.IsValid())<br> return new QVariant();<br> <br> if (role != (int) Qt.ItemDataRole.DisplayRole)<br> return new QVariant();<br> <br> return new QVariant(model[index.Row()][index.Column()].ToString());<br>
<br> }<br> <br> }<br>}<br><br><br>what is wrong in my code ?<br><br><br>angel ignacio colmenares laguado<br>