Skip to content

nodeId parameter is always 0 when read from virtual bool deleteNode(NodeId const nodeId) override #490

Closed

Description

@OpenJowel

Description with steps to reproduce

Hi, first of all, thank you for this beautiful project. It is exactly what I have been looking for.

I am only facing a problem currently, I have been working on a class implementation based on QtNodes::AbstractGraphModel.

Everything was going perfect until I started to handle nodes deletion.
Indeed, when I set a breakpoint in

    bool GraphViewController::deleteNode(QtNodes::NodeId nodeId)
    {
      Logger::debug("Deleting ", nodeId);
     // ...
    }

The nodeId value is always 0 when I delete the node from the UI (selecting node and hitting "delete" key)

However, i am able to refer to proper IDs everywhere else and it's perfect.
(I am simply using an increment value at node creation.)

Am I missing anything ? I am using the version 3.0.12 of the project

Thank you very much,

Cheers

Supporting files, videos and screenshots

Image

Qt Version

6

Operating system

ArchLinux

Additional context

No response

Checklist

  • I have verified that this issue has not been logged before, by searching the issue tracker for similar issues
  • I have attached all requested files and information to this report
  • I have attempted to identify the root problem as concisely as possible, and have used minimal reproducible examples where possible

Activity

  1. OpenJowel commented on Aug 29, 2025

    @OpenJowel
    Author

    For some reasons, the problem was solved by overriding the non-pure "saveNode" method as follow:

    QJsonObject GraphViewController::saveNode(NodeId const nodeId) const
    {
        QJsonObject nodeJson;
    
        nodeJson["id"] = static_cast<qint64>(nodeId);
    
        return nodeJson;
    }
    

    It feels a bit like a positive side effect. Is it normal ? The documentation states:

    inline virtual QJsonObject saveNode(NodeId const) const
    
        Reimplement the function if you want to store/restore the node’s inner state during undo/redo node deletion operations.
    
    

    But doesn't warn clearly about this requirement regarding node id validity at deletion time as it mostly states about undo/redo.

    Well. My problem is solved but the reason is still unclear. The SimpleGraph example helped me well getting over this.

    If you want to reproduce my "bug" scenario, just comment-out the saveNode method from the abovementioned example and observe the ID passed to deleteNode will always be 0.

    If this behavior is purposeful, I would advise to set virtual QJsonObject saveNode(NodeId const) const to pure in the AbstractGraphModel class (or to make it do the bare minimum (such as the implementation above)) as this sounds like a obscure requirement for well-behaving NodeID.

    Else, there might be a bug to fix in order to ensure proper ID at deletion time.

    Thank you for your attention

  2. self-assigned this
    on Nov 23, 2026
  3. paceholder commented on Nov 23, 2026

    @paceholder
    Owner

    Sorry that this stayed unanswered for so long. You found a real bug, and your analysis was right. This is not a side effect you should depend on.

    What happened. The delete command did not take the node id from the graph. It read the "id" key from the JSON that saveNode() returns. The default saveNode() returns an empty object, so the key was missing, and a missing key became id 0. The same failure made undo of a delete and paste of a copied node lose or crash on such models. Your override wrote "id", so it fixed the symptom.

    What changes. #556 makes the library write the node id itself, so deleteNode() gets the real id with the default saveNode(). It also adds tests for delete, undo and paste through the undo stack. They fail on the old code. #557 fixes the same kind of id loss for ids of 2^31 or more on scene load.

    What stays the same. saveNode() and loadNode() are still how undo restores a deleted node. With the defaults, undo of a delete cannot bring the node back, because the library has no other way to create it with its old id. The docs now say this in AbstractGraphModel, in the undo guide and in the FAQ. Making the model interface handle this directly is tracked in #554 for v4.

    I will close this issue when #556 is merged.

  4. added a commit that references this issue on Nov 23, 2026
    0fb64b9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions