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 7878709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:44:08+00:00 2026-06-03T03:44:08+00:00

According to the QGraphicsItem destructor documentation , It is more efficient to remove the

  • 0

According to the QGraphicsItem destructor documentation, “It is more efficient to remove the item from the QGraphicsScene before destroying the item.”

Why is that? I can’t think of how it could make a difference. And if it did make a difference, shouldn’t the QGraphicsItem destructor just call:

if (scene() != NULL)
    scene()->removeItem(this);

I checked the source, and this does not seem to be the case, although sometimes I have a tough time understanding Qt source. EDIT: See comments in jdi’s answer.

  • 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-03T03:44:09+00:00Added an answer on June 3, 2026 at 3:44 am

    Maybe I am interpreting the docs differently than you (I have not looked at the source):

    QGraphicsItem::~QGraphicsItem () [virtual]
    Destroys the QGraphicsItem
    and all its children. If this item is currently associated with a
    scene, the item will be removed from the scene before it is deleted.
    Note: It is more efficient to remove the item from the QGraphicsScene
    before destroying the item.

    I take that to mean it will remove it from the scene first before destroying because that is more efficient. But if you say the source does not indicate anywhere that this occurs, then is seems the docs would be false?

    If I had to take a guess as to why it would be more efficient to remove the item first before destroying it (regardless of whether the API really does it for you in the destructor), I would think it would have to do with what triggers the scene to reindex. Maybe by deleting an item that is still in the scene, the cascading deletions of child items would constantly trigger the scene to reindex. Whereas, if you were to remove the item first, it may efficiently pull out the entire hierarchy in a way that only requires a single update of the scene, and then the normal deletion can occur without further affecting it? There may even be more cascading effects of other child events/signals while they are deleted within the scene.

    I’m betting the logic behind the “Note” is to inform those who would subclass a QGraphicsItem and overload the destructor to keep in mind the need to remove from the scene first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the PHP Documentation PDO::prepare() adds quotes to all your parameters so that
According to the MSDN documentation , a ribbon:RibbonControlSizeDefinition can be used to control the
According to the feedparser documentation , I can turn an RSS feed into a
According to this , ActiveRecord first generates the SQL: SELECT * FROM clients LIMIT
According to this : It is important to note that this is very different
According to this discussion , the iphone agreement says that it doesn't allow loading
According to what I've heard, integer values that are not the processor's word size
According to Steffen's post this is an efficient way to generate random BOOL s
According to the documentation , socket_read() is supposed to return FALSE when the remote
According to be Spring Framework documentation, logging is the only mandatory dependency of Spring.

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.