[Qt-interest] EditableTreeMode example crashing with modeltest

Daniel Price daniel.price at fxhome.com
Tue Nov 24 11:32:18 CET 2009


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

________________________________
This email is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you are not the intended recipient please notify the sender. Please delete the message from all places in your computer where it is stored. You should not copy the email or use it for any purpose or disclose its contents to any other person.To do so may be unlawful. Email is an informal means of communicating and may be subject to data corruption accidentally or deliberately. For this reason it is inappropriate to rely on advice contained in an email without obtaining written confirmation of it first.

FXhome Limited is a limited company registered in England and Wales. Registered number: 04172812. Registered office: The Henderson Business Centre, Ivy Road, Norwich, Norfolk, NR5 8BF, U.K.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091124/fce3d88d/attachment.html 


More information about the Qt-interest-old mailing list