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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:54:36+00:00 2026-05-13T16:54:36+00:00

I come from a fairly strong C background, and have a rather solid foundation

  • 0

I come from a fairly strong C background, and have a rather solid foundation in C++. More recently I’ve been working with C# and other higher level languages. A project I’m looking at working on could really benefit from using QT4, but I have some questions on memory management I can’t seem to understand. I’ve read the QT4 documentation and it hasn’t helped me much. So that is why I’m here.

1) Okay so to start with, I understand that the easiest way to use QT4 objects is to declare them locally:

void MyFunc()
{
     QString foo;
     // do stuff to foo

}

This is simple enough, I can take that object, and pass it around and know that when it goes out of scope it will be destroyed. But here’s my question.

1)If I create a QList and add objects to it, and then the QList goes out of scope, will it try to deallocate the child objects?

2)If a QT4 routine returns a pointer to an object, am I then responsible for the de-allocation of that object?

3)If I create a subclass of a QWidget, and add it to a QWindow, how do I insure that when the QWindow is destroyed, that it takes my widget with it?

Thanks for the help.

  • 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-05-13T16:54:36+00:00Added an answer on May 13, 2026 at 4:54 pm

    If I create a QList and add objects to it, and then the QList goes out of scope, will it try to deallocate the child objects?

    QList is just like std::list. It will destroy the contained objects when it is destroyed.

    If a Qt4 routine returns a pointer to an object, am I then responsible for the de-allocation of that object?

    Usually no, the docs should specify what happens. An exception are the take* functions (e.g: QTableWidget::takeItem).

    If I create a subclass of a QWidget, and add it to a QWindow, how do I insure that when the QWindow is destroyed, that it takes my widget with it?

    It depends on how you create the subclass object.

    • You could add it as a member of the window widget (there is no QWindow, by the way) and it will be destroyed just like any member variable.
    • You could allocate it with new and pass it the window as parent and it will be deleted thanks to the Qt object tree implementation (as cake mentioned)
    • You could do the memory management yourself.

    When a QWidget (or any QObject) is destroyed, it will remove itself from its parent’s to-delete list so you can delete it yourself and not worry about double deletes.

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

Sidebar

Ask A Question

Stats

  • Questions 303k
  • Answers 303k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We have been doing a lot of thinking recently at… May 13, 2026 at 8:43 pm
  • Editorial Team
    Editorial Team added an answer You can use instance_variable_set method by calling on the object… May 13, 2026 at 8:43 pm
  • Editorial Team
    Editorial Team added an answer Static level initialization is a huge compiler-dependent grey area, as… May 13, 2026 at 8:43 pm

Related Questions

I come from a fairly strong OO background, the benefits of OOD & OOP
I have a table like so: Table eventlog user | user_group | event_date |
I have this idea that using SQL VIEWS to abstract simple database computations (such
I'm about to start a fairly Ajax heavy feature in my company's application. What
I have a java application which uses JPA. Say I have an entity called

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.