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

Qt-jambi-interest Archive, February 2007
Model update in QTreeView ?


Message 1 in thread

Hi,

I'm new to QT and Jambi and trying to understand how the model view works  
with trees. In the example below I've created a infinite large tree and  
I'm trying to update the first node each second just to understand how to  
use signals to notify the view that the data has changed. The problem is  
that the dataChanged signal in the model needs two QModelIndex describing  
the area of change and the constructor for QModelIndex is private.

How is this supposed to work ?

-=BÃrge

import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QTreeModel;
import com.trolltech.qt.gui.QTreeView;

public class JambiFileTree {

     private static QTreeView view;
     private static MyModel model;

     public static void main(String args[]) {

         QApplication.initialize(args);

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

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

         new Thread() {

             public void run() {
                 while (true) {
                     try {
                         Thread.sleep(1000);
                     } catch (InterruptedException e) {
                     }

                     QApplication.invokeLater(new Runnable() {
                         public void run() {
                             model.dataChanged. <---- ?????
                         }
                     });
                 }
             }
         }.start();
         QApplication.exec();
     }
}


class MyModel extends QTreeModel {


     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();
     }


}

  ________________________________________________________________________
  BÃrge Nygaard Austvold
  Software Engineer, Poseidon Simulation AS
  Terminalveien 10,n N-8006 BodÃ, Norway

  Mobile : +47 47012347
  E-Mail : bna@xxxxxxxxxxx
  Internet : www.poseidon.no


Message 2 in thread

BÃrge Austvold wrote:
> 
> Hi,
> 
> I'm new to QT and Jambi and trying to understand how the model view 
> works  with trees. In the example below I've created a infinite large 
> tree and  I'm trying to update the first node each second just to 
> understand how to  use signals to notify the view that the data has 
> changed. The problem is  that the dataChanged signal in the model needs 
> two QModelIndex describing  the area of change and the constructor for 
> QModelIndex is private.

The function you're looking for is QAbstractItemModel.createIndex();

http://doc.trolltech.com/qtjambi-1.0/com/trolltech/qt/core/QAbstractItemModel.html#createIndex(int,%20int)

best regards,
Gunnar