[Qt-jambi-interest] QStandardItem setData() fails when invoked twice

Curt Nowak cnowak at bwl.uni-hildesheim.de
Wed Jul 2 11:22:18 CEST 2008


Hi all,
 
I am trying to fill a QStandardItemModel with QStandardItems that contain custom data. Unfortunately I came across a similar outcome as before when I had tried to use a Custom Delegate (see my previous mails "QItemDelegate for *non-primitives* using QComboBox"): There is trouble with non-Qt objects.
It seems you have to create a new instance of QStandardItem every time the content of your model changes.  Is that the very same bug as before or a new issue?
My system runs with JRE 1.6.0, Jambi 4.4, and Windows XP.
 
The following is a very small sample program that shows what I mean.

import java.awt.Point;
import com.trolltech.qt.core.Qt;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QStandardItem;

public class SetDataSample
{
    public static void main(String args[])
    {
        QApplication.initialize(args);
        SetDataSample sample = new SetDataSample();
        QApplication.exec();
    }
    
    public SetDataSample()
    {
        Point point1 = new Point(1,1);
        Point point2 = new Point(2,2);
        Integer int3 = new Integer(3);  // Qt seems to be able to cast Integer into something it understands
        
        // Round 1
        QStandardItem item = new QStandardItem();
        item.setData(point1, Qt.ItemDataRole.UserRole);
        Object debug1 = item.data(Qt.ItemDataRole.UserRole);
        System.out.println(debug1);                                    // success: "java.awt.Point[x=1,y=1]"
        
        // Round 2
        item.setData(point2, Qt.ItemDataRole.UserRole);                // trying to change the data
        Object debug2 = item.data(Qt.ItemDataRole.UserRole);
        System.out.println(debug2);                                    // failure: "java.awt.Point[x=1,y=1]" instead of "java.awt.Point[x=2,y=2]"
        
        // Round 3 - this time with Integer (Qt seems to be able to cast that into something it understands)
        item.setData(int3, Qt.ItemDataRole.UserRole);                // trying to change the data
        Object debug3 = item.data(Qt.ItemDataRole.UserRole);
        System.out.println(debug3);                                    // success: "3"
    }
}


Curt
 
 




More information about the Qt-jambi-interest mailing list