--===============0836322338==
Content-Type: multipart/alternative; boundary=0016364d2121bdaf9c046d1efde2
--0016364d2121bdaf9c046d1efde2
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
i am implementing a custom model using a System.Data.DataTable, but get
this error:
Fatal error: C# instance has been wrongly GC'd for virtual
0xa3fa3f8->QAbstractItemModel::rowCount(const QModelIndex&) const call.
this is the code:
using System;
using Qyoto;
namespace qtnet
{
public class TableModelSample
{
private QTableView view;
private TableModel model;
public TableModelSample()
{
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("Name");
table.Columns.Add("Age");
for(int i=0 ; i<1000; i++){
System.Data.DataRowView drv = table.DefaultView.AddNew();
drv.BeginEdit();
drv["Name"]=String.Format("name for {0} is = ", i );
drv["Age"] =String.Format("age for {0} is = ", i );
drv.EndEdit();
}
model= new TableModel(table.DefaultView);
view = new QTableView();
view.SetModel(model);
view.WindowTitle = "Simple Table Model";
view.Show();
}
public static int Main(string[] args){
new QApplication(args);
new TableModelSample();
return QApplication.Exec();
}
}
public class TableModel:QAbstractTableModel{
System.Data.DataView model;
public TableModel(System.Data.DataView model, QObject parent) :
base(parent){
this.model=model;
}
public TableModel(System.Data.DataView
model):this(model,(QObject)null){
}
public override int RowCount (QModelIndex parent)
{
return model.Count;
}
public override int ColumnCount(QModelIndex parent){
return this.model.Table.Columns.Count;
}
public override QModelIndex Parent(QModelIndex index) {
return new QModelIndex();
}
public override QVariant Data(QModelIndex index, int role) {
if (!index.IsValid())
return new QVariant();
if (role != (int) Qt.ItemDataRole.DisplayRole)
return new QVariant();
return new QVariant(model[index.Row()][index.Column()].ToString());
}
}
}
what is wrong in my code ?
angel ignacio colmenares laguado
--0016364d2121bdaf9c046d1efde2
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
i am implementing a custom model using a System.Data.DataTable, but get
=
this error:
Fatal error: C# instance has been wrongly =
GC'd for virtual 0xa3fa3f8->QAbstractItemModel::rowCount(const QMode=
lIndex&) const call.
this is the code:
using System;
using Qyoto;
namespace qtn=
et
{
=A0=A0=A0
=A0=A0=A0 public class TableModelSample
=A0=A0=
=A0 {
=A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 private QTableView vie=
w;
=A0=A0=A0 =A0=A0=A0 private TableModel model;
=A0=A0=A0 =A0=A0=A0 public TableModelSample()
=A0=A0=A0 =A0=A0=A0 {
=
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 System.Data.DataTable table =3D new System.Da=
ta.DataTable();
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 table.Columns.Add("Na=
me");
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 table.Columns.Add("Age&quo=
t;);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 for(int i=
=3D0 ; i<1000; i++){
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0 System.Data=
.DataRowView drv =3D table.DefaultView.AddNew();
=A0=A0=A0 =A0=A0=A0 =A0=
=A0=A0 =A0=A0 drv.BeginEdit();
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0 drv[=
"Name"]=3DString.Format("name for {0} is =3D ", i );
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0 drv["Age"] =3DString.Format(=
"age for {0} is =3D ", i );
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=
=A0 drv.EndEdit();
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=
=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 model=3D new TableModel(tab=
le.DefaultView);
=A0=A0=A0 =A0=A0=A0 =A0 =A0 view =3D new QTableView();<=
br>
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 view.SetModel(model);
=A0=A0=A0 =A0=A0=A0 =
=A0=A0=A0 view.WindowTitle =3D "Simple Table Model";
=A0=A0=A0=
=A0=A0=A0 =A0=A0=A0 view.Show();
=A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0=
=A0=A0=A0 public static int Main(string[] args){
=A0=A0=A0=A0=A0 =A0=A0=
=A0 =A0=A0=A0 new QApplication(args);
=A0=A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 new TableModelSample();
=A0=A0=A0=A0=
=A0 =A0=A0=A0 =A0=A0=A0 return QApplication.Exec();
=A0=A0=A0 =A0=A0=A0 =
}
=A0=A0=A0
=A0=A0=A0 }
=A0=A0=A0
=A0=A0=A0 public class Tabl=
eModel:QAbstractTableModel{
=A0=A0=A0 =A0=A0=A0 System.Data.DataView mod=
el;
=A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 public TableModel(System.Data.DataView model, QObject p=
arent) : base(parent){
=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0 this.model=3Dmode=
l;
=A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 =
public TableModel(System.Data.DataView model):this(model,(QObject)null){
=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=
=A0=A0
=A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 public override int =
RowCount (QModelIndex parent)
=A0=A0=A0 =A0=A0=A0 {=A0=A0=A0 =A0=A0=A0 =
=A0=A0=A0
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 return model.Count;
=A0=A0=
=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 public overr=
ide int ColumnCount(QModelIndex parent){
=A0=A0=A0 =A0=A0=A0=A0=A0=A0 return this.model.Table.Columns.Count;
=A0=
=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0 public override QModelIndex P=
arent(QModelIndex index) {
=A0=A0=A0 =A0=A0=A0=A0=A0 return new QModelIn=
dex();
=A0=A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0=A0 =A0=A0=A0
=A0=A0=A0=
=A0 =A0=A0=A0 public override QVariant Data(QModelIndex index, int role) {<=
br>
=A0=A0=A0 =A0=A0=A0 if (!index.IsValid())
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =
return new QVariant();
=A0=A0=A0 =A0=A0=A0
=A0=A0=A0 =A0=A0=A0 if (r=
ole !=3D (int) Qt.ItemDataRole.DisplayRole)
=A0=A0=A0 =A0=A0=A0 =A0=A0=
=A0 return new QVariant();
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0
=
=A0=A0=A0 =A0=A0=A0 return new QVariant(model[index.Row()][index.Column()].=
ToString());
=A0=A0=A0 =A0=A0
=A0=A0=A0 =A0=A0 }
=A0=A0=A0 =A0=A0=A0
=A0=A0=
=A0 }
}
what is wrong in my code ?
angel ignacio c=
olmenares laguado
--0016364d2121bdaf9c046d1efde2--
--===============0836322338==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Kde-bindings mailing list
Kde-bindings@kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
--===============0836322338==--