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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:09:31+00:00 2026-06-08T02:09:31+00:00

I have been reading Qt documentation and playing around with the qobject tree. I

  • 0

I have been reading Qt documentation and playing around with the qobject tree. I was wondering if there is a way to remove widgets from inside the tree that would delete them from memory.

When embedding qwidgets/qobjects in each other and creating the tree, removing a widget with removeWidget from the qlayouts would remove them visually in the gui however the object still remains attached to the parent qobject (object->parent() is not 0), it will only be deleted once its parent is deleted (such as going out of scope). I can only see that an qwidget can be destroyed only once the application terminates where the top widget wills everything underneath it (or if the object goes out of scope).

For example, say have a main window that has 2 stages: the first one has about 100 objects embedded from one parent and the other has 200. The application starts at stage 1 and moves to stage 2 where it will never go back to stage 1. If I wanted this to be somewhat efficient, I would try to kill all the objects in stage 1 (100 objects) but because they are attached to the root node of the main window, it cannot be destroyed even using “removeWidget”.

I also tried to receive the pointer of a widget that was created without “new” operator and if I delete that object, the application would crash because it would call the destructor twice.

My question is, is there a way to remove a node in the qobject tree (where that node is not deleted because it is out of scope or when the application terminates)?

Sorry if this does not make that much sense. Thanks in advance.

Edit:

Sorry if I have given the wrong idea. My question is to remove a node from memory before the application terminates or before the object goes out of scope. This is an example (probably not that good).

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Test w;
    w.show();

    QHBoxLayout *layout = new QHBoxLayout();
    w.setLayout(layout);

    Test heavyObj;             //I know you can use pointers instead and that 
                               //would allow you to easy delete the object
                               //but say if I did this instead.
    w->addWidget(&heavyObj);

    for(int i=0; i < 200; i++) {
        Test obj(heavyObj);
    }

    w->removeWidget(&heavyObj); //At this point we don't want "heavyObj", I want
                                //to delete this object from memory
                                // is it possible to remove p1 from memory?

    return a.exec();

    //As stated, once the program terminates everything is destroyed
}
  • 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-08T02:09:33+00:00Added an answer on June 8, 2026 at 2:09 am

    After calling removeWidget(), delete the object with delete yourWidgetPointer;. The destructor of the QObject will take care of unregistering the child with the parent.

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

Sidebar

Related Questions

What I have been able to grasp from reading the source and documentation from
I have been reading the Android documentation and I am wondering if anyone can
I have been reading through the documentation on the JavaScriptMVC framework and it looks
hello im new to python and have been reading over the documentation and am
I have been reading documentation describing class inheritance, abstract base classes and even python
I have been reading through the core data documentation and feel I am still
I have been reading the API and documentation ( http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Analysis.doc.html 9.5 Edge Detection) and
I've been playing around a bit with the Tornado web server and have come
I have been reading documentation about the new features that IIS 7.5 offers regarding
I am new to Propel and have been reading the documentation. But, I have

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.