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

  • Home
  • SEARCH
  • 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 650529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:03:47+00:00 2026-05-13T22:03:47+00:00

I’ve got a Qt App that uses QPointers to bring up new UI Dialogs

  • 0

I’ve got a Qt App that uses QPointers to bring up new UI Dialogs (Widgets). The main app can have numerous of the same widget loaded with different data. The problem I’m having is in deleting and freeing the memory for each widget. If I monitor the RAM usage of the program, each time I click the button to open one of these new widgets, it increases the ram and when I close the widget, it doesn’t seem to be freeing the ram. I’ve tried using deleteLater and other solutions but keep getting crashes in the program.

Some example code is here:

QPointer<ListReservations> listResWindow = new ListReservations(resID);
listResWindow->setNum(numpeople);
listResWindow->show();

This will call the “ListReservations” widget which is declared as a QDialog (NOT modal). In that dialog I then have a button to close the window that calls the QWidget::close() slot.

I guess the question is how does my main program (that has the QPointer) know when the dialog is closed and then free the dialog and (if possible) delete the pointer to save even more memory…

I thought you might be able to do a QConnect() to the QPointer object, but I can’t seem to find any signals or slots that would allow the passing of the pointer, much less send the signal once the dialog is indeed closed and ready for deletion.

Maybe I need some sort of function in the main program that takes a generic pointer object and then have the QDialog call that before calling it’s own close slot? In that function it would pass itself to be destroyed? Just throwing out ideas that I’ve tried to implement but failed at….

I don’t think I can reuse the same pointer elsewhere because in theory you could have multiple ListReservations windows open at the same time.

  • 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-13T22:03:47+00:00Added an answer on May 13, 2026 at 10:03 pm

    Make sure that you set the Qt::WA_DeleteOnClose attribute flag on your dialog using QWidget::setAttribute(). That should make sure that the dialog is properly destroyed when it is closed. See the Qt documentation for more details.

    Assuming that memory is now properly freed, the pointer should invalidate itself, from the Qt documentation:

    A guarded pointer, QPointer,
    behaves like a normal C++ pointer T *,
    except that it is automatically set to
    0 when the referenced object is
    destroyed (unlike normal C++ pointers,
    which become “dangling pointers” in
    such cases)

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

Sidebar

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.