[Qt-interest] EditableTreeMode example crashing with modeltest

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Wed Nov 25 00:55:27 CET 2009


Hi Daniel, 
 
My understanding is that QAbstractItemModel supports infinitely nested
spreadsheet cells - so any cell can be a parent.  The hard part is how to
represent this to the user, in a meaningful way.  None of the supplied views
support this degree of flexibility.  
 
I think QTreeView allows only one column to be nested, and it is the first
column by convention, but I can't find where I read that in assistant.
Maybe ModelTest is a bit too strict in that case?  The test in your index
routine is just enforcing that ModelIndex's to parent's are to its first
column.  
 
I haven't found a good example of a Qt model representing a dozen different
business objects and their relationships.  Hopefully Bill King's work will
remedy that... ;O)
 
Unfortunately, QTreeView is also very ROW based.  For example, it doesn't
allow the background of the parent to extend beneath its visible children.
You can't change the drop indicators that are drawn, etc.  Reimplementing
QTreeView is much easier said than done! 
 
Tony
 

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Daniel Price
Sent: Tuesday, 24 November 2009 21:32
To: qt-interest List
Subject: [Qt-interest] EditableTreeMode example crashing with modeltest



I'm writing a tree model and I've used the Qt EditableTreeModel example
(4.5.2)  as a guide.

 

My model works fine when I had only one column of data but then behaves
strangely when I have more than one column (child items added under other
tree items do not always show up in the view). 

 

I hooked up Qt's modeltest project
(http://labs.trolltech.com/page/Projects/Itemview/Modeltest) and I don't get
any errors or problems with one column when inserting child items. But with
two columns of data, it asserts on line 328 with the test "index.isValid()
== true" .

 

This code appears to the culprit:

 

QModelIndex TreeModelAdaptor::index(int row, int column, const QModelIndex
&parent) const

{

                if (parent.isValid() && parent.column() != 0)

                                return QModelIndex();

 

                ....

}

 

This was copied from the example - the test passes in a valid parent with a
non-zero column and gets back an invalid model index, triggering the assert.
But my model code is almost identical  to the example.

 

Can someone explain this code? Why does the code return the root item in
this case?

 

So I tried hooking up EditableTreeModel to ModelTest in MainWindow.cpp:

 

...

 QFile file(":/default.txt");

                 file.open(QIODevice::ReadOnly);

                 TreeModel *model = new TreeModel(headers, file.readAll());

                  file.close();

 

new ModelTest(model, this);

 

                view->setModel(model);

...

 

And it crashes at startup. Even with no data, the example crashes when used
with ModelTest (in the debugger it  breaks on qMalloc()).

 

Have the Qt examples been verified with ModelTest? Any idea as to what is
going on?

 

 

 

Daniel Price

Software Engineer

FXhome Limited

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091125/168b0cc2/attachment.html 


More information about the Qt-interest-old mailing list