[Kde-bindings] [Bug 197103] New: [qyoto] Application crashes when expanding 2nd level nodes in a QTreeView

ttmails2 at gmx.de ttmails2 at gmx.de
Fri Jun 19 06:14:26 UTC 2009


https://bugs.kde.org/show_bug.cgi?id=197103

           Summary: [qyoto] Application crashes when expanding 2nd level
                    nodes in a QTreeView
           Product: bindings
           Version: unspecified
          Platform: Compiled Sources
        OS/Version: Linux
            Status: UNCONFIRMED
          Severity: crash
          Priority: NOR
         Component: general
        AssignedTo: kde-bindings at kde.org
        ReportedBy: ttmails2 at gmx.de


Version:            (using Devel)
Compiler:          i686-pc-linux-gnu-4.3.3 -O2 -mtune=core2 -march=core2
-fomit-frame-pointer -pipe
OS:                Linux
Installed from:    Compiled sources

I am able to reproduce this _always_ using the following code:

(I tried to cut it down to the necessary parts, but needed a custom tree model)

using System;
using System.Collections.Generic;

using Qyoto;

public class Editor
{
    public static int Main(String[] args)
    {
        new QApplication(args);

        QTreeView tv = new QTreeView();
        ItemModel model = new ItemModel();
        tv.SetModel(model);
        tv.Show();

        return QApplication.Exec();
    }
}

public class ItemModel : QAbstractItemModel
{
    public ItemModel () : base()
    {
    }

    public override int RowCount (Qyoto.QModelIndex parent)
    {
        if (!parent.IsValid())
        {
            // this is the number of projects
            return 1;
        }

        return ((Node)parent.InternalPointer()).RowCount();
    }

    public override QVariant Data (Qyoto.QModelIndex index, int role)
    {
        if (role == (int)ItemDataRole.DisplayRole)
        {
            return "node";
        }

        return new QVariant();
    }

    public override QModelIndex Parent (Qyoto.QModelIndex child)
    {
        Node node = (Node)child.InternalPointer();
        node = node.Parent();

        if (null == node)
        {
            // project nodes have no parent
            return new QModelIndex();
        }

        return this.CreateIndex(node.Row(), 0, node);
    }

    public override QModelIndex Index (int row, int column, Qyoto.QModelIndex
parent)
    {
        Node node;

        if (parent.IsValid())
        {
            node = ((Node)parent.InternalPointer()).ChildAt(row);
        }
        else
        {
            // create a new project node
            node = new Node("/", row);
        }

        return this.CreateIndex(row, column, node);
    }

    public override int ColumnCount (Qyoto.QModelIndex parent)
    {
        return 1;
    }
}

public class Node
{
    private string path;

    private int row;

    private Node parent;

    private List<Node> children;

    public Node(string path, int row)
    {
        this.path = path;
        this.row = row;
    }

    public Node(string path, int row, Node parent) : this(path, row)
    {
        this.parent = parent;
    }

    public Node Parent()
    {
        return parent;
    }

    public string Path()
    {
        return path;
    }

    public int Row()
    {
        return row;
    }

    public int RowCount()
    {
        return Children().Count;
    }

    // fetch all sub-directories and files
    protected List<Node> Children()
    {
        if (null == children)
        {
            QDir dir = new QDir(Path());
            dir.SetFilter((uint)(QDir.Filter.NoDotAndDotDot |
QDir.Filter.AllEntries));

            QDirIterator it = new QDirIterator(dir);

            children = new List<Node>();
            while (it.HasNext())
            {
                children.Add(new Node(it.Next(), children.Count, this));
            }
        }

        return children;
    }

    public Node ChildAt(int index)
    {
        return Children()[index];
    }
}

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the Kde-bindings mailing list