Note that there are some explanatory texts on larger screens.

plurals
  1. POQTreeView insertRows via method crushs / direct call works
    primarykey
    data
    text
    <p>I have following strange problem.</p> <p>I've implemented a QAbstractItemModel to the point that I can insert child nodes to the tree view but something strange occurs when I try to add the nodes via the insertRows() method. </p> <p>First where all is called:</p> <pre><code>QApplication a(argc, argv); QResource::registerResource("Qt5Tutorial.rcc"); QTreeView *treeView = new QTreeView(); treeView-&gt;show(); Node rootNode("rootNode"); CameraNode childNode0("childNode0", &amp;rootNode); CameraNode childNode1("childNode1", &amp;rootNode); LightNode childNode2("childNode2", &amp;rootNode); CameraNode childNode3("childNode3", &amp;childNode0); TransformNode childNode4("childNode4", &amp;childNode2); TransformNode tryNode("potato"); // setup model ObjectTreeModel model(&amp;rootNode); treeView-&gt;setModel(&amp;model); // insert directly via the insert child method // this works! childNode0.insertChild(1, &amp;tryNode); // get the QModelIndex of childNode1 // must be passed in the insertRows() method QModelIndex index(model.index(1, 0, QModelIndex())); // the output is "childNode1" what is totally right qDebug() &lt;&lt; "index: "&lt;&lt;static_cast&lt;Node*&gt;(index.internalPointer())-&gt;getName(); // output see posted beneath qDebug() &lt;&lt; rootNode.log(); // should insert in "childNode1" -&gt; at 0th position and just 1 Node object // see the method beneath model.insertRows(0, 1, index); // if i try to call the method rootNode.log(); now again, it crashes return a.exec(); </code></pre> <p>This is the output from the rootNode.log() call:</p> <pre><code>---rootNode ---childNode0 ---childNode3 ---potato ---childNode1 ---childNode2 ---childNode4 </code></pre> <p>As you can see the "Potato" Node is correctly inserted. </p> <p>View an image <a href="http://www10.pic-upload.de/04.01.13/m65huuqq4ruu.png" rel="nofollow">http://www10.pic-upload.de/04.01.13/m65huuqq4ruu.png</a></p> <p>But once I try to expand the childNode1 node it crashes. But look at the last comment in the code above. As i mentioned -> if i try to output the tree view now (it iterates through all nodes) it crashes.</p> <p>When the method is called everything seems to be ok - just when i try to expend the tree view it crashes -> the debug output let me think that all should be ok</p> <p>The actual error message is a access violation when reading at position ... (translated from German - don't know if its called the same in English)</p> <pre><code> bool ObjectTreeModel::insertRows(int position, int row, const QModelIndex &amp;parent) { beginInsertRows(parent, position, position + row - 1); Node *parentNode = getNode(parent); qDebug() &lt;&lt; "parentName: " &lt;&lt; parentNode-&gt;getName(); bool success = false; for(int i = position; i &lt; row; i++) { qDebug() &lt;&lt; "inside loop"; qDebug() &lt;&lt; "position: " &lt;&lt; position &lt;&lt; "row: " &lt;&lt; row; TransformNode childNode("insertedNode"); success = parentNode-&gt;insertChild(i, &amp;childNode); qDebug() &lt;&lt; "success: " &lt;&lt; success; } endInsertRows(); return success; </code></pre> <p>}</p> <p>The debug output for the method above:</p> <pre><code>getNode: successful parentName: "childNode1" inside loop position: 0 row: 1 called inserchild success: true </code></pre> <p>I have no idea why this happens becuase the debug output seems right and it should be basically the same as insert the node directly via the insertChild method.</p> <p>I hope that someone has an idea why it doesn't work.</p> <p>Best regards, Michael </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload