Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, February 2007
VM Crash when sending dataChanged signal to QTreeView


Message 1 in thread

This snippet of codes crashes on my java 6 VM on linux

-=Børge


public class JambiFileTree {

    public static void main(String args[]) {

        QApplication.initialize(args);

        QTreeView view = new QTreeView();
        MyModel model = new MyModel();

        view.setModel(model);
        view.show();

        QApplication.exec();
    }
}


class MyModel extends QTreeModel implements Runnable{


    public MyModel() {
        new Thread(this).start();
    }

    public Object child(Object object, int i) {



        return "Test " + i + "(" + System.currentTimeMillis() + ")";
    }

    public int childCount(Object object) {
        return 10;
    }

    public String text(Object object) {
        return object.toString();
    }


    public void run() {

        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            Runnable runnable = new Runnable() {
                public void run() {
                    dataChanged.emit(createIndex(0, 0), createIndex(1, 0));
                }
            };
            QApplication.invokeLater(runnable);
        }
    }
}

#
# An unexpected error has been detected by Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0xac2cb1d0, pid=9348, tid=3085052816
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode)
# Problematic frame:
# C  [libcom_trolltech_qt_gui.so.1.0.0+0x3391d0]  _ZNK10QTreeModel4nodeERK11QModelIndex+0x40
#
# An error report file with more information is saved as hs_err_pid9348.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#


Message 2 in thread

Børge Austvold wrote:

>This snippet of codes crashes on my java 6 VM on linux
>  
>
[...]

>        while (true) {
>            try {
>                Thread.sleep(1000);
>            } catch (InterruptedException e) {
>            }
>            Runnable runnable = new Runnable() {
>                public void run() {
>

dataChanged.emit(index(0, 0, null), index(1, 0, null));

>                }
>            };
>            QApplication.invokeLater(runnable);
>        }
>    }
>}
>  
>

Hi, Børge.

This is due to a bug in the QTreeModel. Because of this bug you can 
unfortunately not use createIndex() to create new model indices.

Could you use index() instead, as indicated above? The last "null" 
parameter is the parent node of the rows to be updated in the tree 
structure. Passing "null" here selects the root node.

-- Eskil


Message 3 in thread

On Fri, 16 Feb 2007 16:42:53 +0100, Eskil A. Blomfeldt wrote:

> Børge Austvold wrote:
> 
>>This snippet of codes crashes on my java 6 VM on linux
>>  
>>
> [...]
> 
>>        while (true) {
>>            try {
>>                Thread.sleep(1000);
>>            } catch (InterruptedException e) {
>>            }
>>            Runnable runnable = new Runnable() {
>>                public void run() {
>>
> 
> dataChanged.emit(index(0, 0, null), index(1, 0, null));
> 
>>                }
>>            };
>>            QApplication.invokeLater(runnable);
>>        }
>>    }
>>}
>>  
>>
> 
> Hi, Børge.
> 
> This is due to a bug in the QTreeModel. Because of this bug you can 
> unfortunately not use createIndex() to create new model indices.
> 
> Could you use index() instead, as indicated above? The last "null" 
> parameter is the parent node of the rows to be updated in the tree 
> structure. Passing "null" here selects the root node.
> 
> -- Eskil


Hi,

This did work, but I guess I still don't understand how the signals work in this model. I guess when you resize the window
the text() method should be called as the painter probably don't cash this information. In my mind I thought that when you 
emit the dataChanged signal the model should be invoked to get the new object using the public Object child(Object object, int i)

In my example this is not the case.

Can you briefly describe to me how I can

1. Insert, remove objects from the model and emit signals to notify the change ?
2. Change objects and emit signals to notify the change?
3. I've noticed that level1 (toplevel) and level2 are cached. How does this work ?

PS! If i insert a System.out.printlin() in the public Object child(Object object, int i) in the model the VM crashes :(

Thanks

-=Børge 



Message 4 in thread

> 1. Insert, remove objects from the model and emit signals to notify the change ?

Hii Børge,

You should be able to use the QTreeModel.childrenRemoved() and 
QTreeModel.childrenInserted() functions for this. Of course you need the 
object -> index function to call this if you only have objects, and such 
a function is currently missing in the API.

> 2. Change objects and emit signals to notify the change?

There is the function QAbstractItemModel.dataChanged() to notify that 
the values in a particular object changed, but there is currently no 
overload that takes the actual object. I'll see if we can get that into 
the API...

> 3. I've noticed that level1 (toplevel) and level2 are cached. How does this work ?

QAbstractItemModel declares a function hasChildren(QModelIndex) which 
can be used to indicate wether a node should have the "+" or if its a 
leaf. This is currently not implemented so instead we cache one level 
deeper then what is currently visible. We do however intend to implement 
the hasChildren method in the near future so expect this behaviour to 
change.

> PS! If i insert a System.out.printlin() in the public Object child(Object object, int i) in the model the VM crashes :(

I had a lot of those in place when I wrote the QTreeModel and didn't 
experience that then. I also cannot reproduce this with the 
com.trolltech.examples.TreeModel example in the package...

-
Best regards,
Gunnar


Message 5 in thread

Hi Gunnar,

So the preffered way is to use methods and not signals ?

The dataChanged() method in QAbstractItemModel is privat. Are you just 
emmitting signals in this method ? If so, why can't I do it from the 
dataChanged signal ?

The core dump was kind of my fault... I emmitted the dataChanged signal with 
a to large area 0 -> 10 not 0 -> 9 (Maybe an exception should have been 
raised ?)

-=Børge


"Gunnar Sletta" <gunnar@xxxxxxxxxxxxx> wrote in message 
news:45D963B7.10605@xxxxxxxxxxxxxxxx
>
>> 1. Insert, remove objects from the model and emit signals to notify the 
>> change ?
>
> Hii Børge,
>
> You should be able to use the QTreeModel.childrenRemoved() and 
> QTreeModel.childrenInserted() functions for this. Of course you need the 
> object -> index function to call this if you only have objects, and such a 
> function is currently missing in the API.
>
>> 2. Change objects and emit signals to notify the change?
>
> There is the function QAbstractItemModel.dataChanged() to notify that the 
> values in a particular object changed, but there is currently no overload 
> that takes the actual object. I'll see if we can get that into the API...
>
>> 3. I've noticed that level1 (toplevel) and level2 are cached. How does 
>> this work ?
>
> QAbstractItemModel declares a function hasChildren(QModelIndex) which can 
> be used to indicate wether a node should have the "+" or if its a leaf. 
> This is currently not implemented so instead we cache one level deeper 
> then what is currently visible. We do however intend to implement the 
> hasChildren method in the near future so expect this behaviour to change.
>
>> PS! If i insert a System.out.printlin() in the public Object child(Object 
>> object, int i) in the model the VM crashes :(
>
> I had a lot of those in place when I wrote the QTreeModel and didn't 
> experience that then. I also cannot reproduce this with the 
> com.trolltech.examples.TreeModel example in the package...
>
> -
> Best regards,
> Gunnar 



Message 6 in thread

BXrge Austvold wrote:
> Hi Gunnar,
> 
> So the preffered way is to use methods and not signals ?

To notify the QTreeModel of the insertions and removals it is. This will 
in turn trigger the signals in QAbstractItemModel.

> The dataChanged() method in QAbstractItemModel is privat. Are you just 
> emmitting signals in this method ? If so, why can't I do it from the 
> dataChanged signal ?

What do you mean?

dataChanged() is declared as

     public final Signal2<com....

in QAbstractItemModel.java

> The core dump was kind of my fault... I emmitted the dataChanged signal with 
> a to large area 0 -> 10 not 0 -> 9 (Maybe an exception should have been 
> raised ?)

We'll see what can be done with that...

-
Gunnar


Message 7 in thread

>
> What do you mean?
>
> dataChanged() is declared as
>
>     public final Signal2<com....
>
> in QAbstractItemModel.java
>


The method is private in my jar file:

private final void dataChanged(com.trolltech.qt.core.QModelIndex 
qModelIndex, com.trolltech.qt.core.QModelIndex qModelIndex1) { /* compiled 
code */ }

...however the signal is public. The problem is that when I emit a signal 
that some data has changed only the public abstract java.lang.String 
text(java.lang.Object object) in the QTreeModel is invoked. Is't this 
suppose to query the model for the new object using the public Object 
child(Object object, int i) first?

-=Børge 



Message 8 in thread

Hi,
A good lunch solved this one... I guess I misunderstood, the object 
reference to the object returned from child(Object object, int i) should 
ofcourse never change. Therefor the calling the text(...) method is enought 
after an object has been changed.

-=Børge

"Børge Austvold" <bna@xxxxxxxxxxx> wrote in message 
news:erbqb4$47h$1@xxxxxxxxxxxxxxxxxxxxx
>
>>
>> What do you mean?
>>
>> dataChanged() is declared as
>>
>>     public final Signal2<com....
>>
>> in QAbstractItemModel.java
>>
>
>
> The method is private in my jar file:
>
> private final void dataChanged(com.trolltech.qt.core.QModelIndex 
> qModelIndex, com.trolltech.qt.core.QModelIndex qModelIndex1) { /* compiled 
> code */ }
>
> ...however the signal is public. The problem is that when I emit a signal 
> that some data has changed only the public abstract java.lang.String 
> text(java.lang.Object object) in the QTreeModel is invoked. Is't this 
> suppose to query the model for the new object using the public Object 
> child(Object object, int i) first?
>
> -=Børge
>