Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9088815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:59:21+00:00 2026-06-16T21:59:21+00:00

I have following strange problem. I’ve implemented a QAbstractItemModel to the point that I

  • 0

I have following strange problem.

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.

First where all is called:

QApplication a(argc, argv);

QResource::registerResource("Qt5Tutorial.rcc");

QTreeView *treeView = new QTreeView();
treeView->show();

Node rootNode("rootNode");
CameraNode childNode0("childNode0", &rootNode);
CameraNode childNode1("childNode1", &rootNode);
LightNode childNode2("childNode2", &rootNode);
CameraNode childNode3("childNode3", &childNode0);
TransformNode childNode4("childNode4", &childNode2);
TransformNode tryNode("potato");

// setup model
ObjectTreeModel model(&rootNode);
treeView->setModel(&model);

// insert directly via the insert child method 
// this works!
childNode0.insertChild(1, &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() << "index: "<<static_cast<Node*>(index.internalPointer())->getName();

// output see posted beneath
qDebug() << rootNode.log();

// should insert in "childNode1" -> 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();

This is the output from the rootNode.log() call:

---rootNode
    ---childNode0
            ---childNode3
            ---potato
    ---childNode1
    ---childNode2
            ---childNode4

As you can see the “Potato” Node is correctly inserted.

View an image
http://www10.pic-upload.de/04.01.13/m65huuqq4ruu.png

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.

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

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)

 bool ObjectTreeModel::insertRows(int position, int row, const QModelIndex &parent)
{
beginInsertRows(parent, position, position + row - 1);

Node *parentNode = getNode(parent);
qDebug() << "parentName: " << parentNode->getName();

bool success = false;
for(int i = position; i < row; i++)
{

    qDebug() << "inside loop"; 
    qDebug() << "position: " << position << "row: " << row;

    TransformNode childNode("insertedNode");
    success = parentNode->insertChild(i, &childNode);

    qDebug() << "success: " << success;
}

endInsertRows();

return success;

}

The debug output for the method above:

getNode: successful 
parentName: "childNode1" 
inside loop 
position:  0 row:  1 
called inserchild 
success:  true 

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.

I hope that someone has an idea why it doesn’t work.

Best regards, Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:59:22+00:00Added an answer on June 16, 2026 at 9:59 pm

    Almost everything is correct. Just this two lines not:

    TransformNode *childNode = new TransformNode("insertedNode");
    success = parentNode->insertChild(i, childNode);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following strange problem in Oracle (Please keep in mind that I
I've run into a strange problem with Ruby that I can't explain. I have
I am having a strange problem which I don't understand. I have the following
I have a strange problem. I have the following piece of code in C++:
I have a very strange problem and the following code wont compile: #ifndef MYWINDOW_HPP_INCLUDED
I have a 'strange' problem, the following code converts the location lat value into
I have this strange problem in my unit tests. See the following code _pos
I have a strange problem. Afaik I can inject a SessionScoped bean into a
I have a strange problem, will appreciate if anyone can help. I have the
I have a strange problem with the following code: MembersDetailViewController *m = [[MembersDetailViewController alloc]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.