[Kde-bindings] Qyoto: System.Data.DataTable as model for QTableVie

angel ignacio colmenares laguado angel.ignacio.colmenares at gmail.com
Wed Jun 24 21:43:00 UTC 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20090624/4e06ba03/attachment.html>


More information about the Kde-bindings mailing list