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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:28:31+00:00 2026-05-23T14:28:31+00:00

In my current project, I have an array of QCheckBoxes that I create at

  • 0

In my current project, I have an array of QCheckBoxes that I create at run-time given the dimensions from the user. Every time the user clicks the ‘Generate’ button, the dimensions that they inputted are gathered, and an array of QCheckBoxes is created. It is done in the following code:

void MainWindow::on_generateBoxes_clicked()
{
    int x_dim = ui->xDim->value();
    int y_dim = ui->yDim->value();
    int z_dim = ui->zDim->value();

    for(int i = 0; i < x_dim; ++i){
        for(int j = 0; j < y_dim; ++j){
            checkBoxVector.append(new QCheckBox( ui->dim1 ));
            checkBoxVector.last()->setGeometry(i * 20, j * 20, 20, 20);
        }
    }
}

checkBoxVector is a global array of pointers declared in another source file:

QVector<QCheckBox*> checkBoxVector;

My question is, how would I go through checkBoxVector to remove every QCheckBox? Since the previous dimensions of the array are local variables that are lost once the function returns, when it is re-called how would I know how many elements to remove?

If the user was to press the ‘Generate’ button twice there would be overlapping QCheckBoxes, so I need to wipe them all every time the function is called. (Also, nobody wants a memory leak!)

  • 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-23T14:28:31+00:00Added an answer on May 23, 2026 at 2:28 pm

    First delete all the elements (QCheckBoxes) in the vector and then clear the vector:

    qDeleteAll(checkBoxVector);
    checkBoxVector.clear();
    

    Because you are adding checkbox pointers to the vector, just clearing the vector doesn’t delete the checkboxes.

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

Sidebar

Related Questions

In my current project i have to transfer data EVERY DAY from MS Access
I have a spec in my current project that requires us to advise the
In a current (C#) project we have a 3rd party assembly that contains a
I have a requirement on my current project (a Flex app which will be
I am hosting SpiderMonkey in a current project and would like to have template
I am using a Cairngorm MVC architecture for my current project. I have several
OK, another road bump in my current project. I have never had form elements
I have a fairly standard inheritance situation in my current LINQ-to-SQL project. I have
My current project is in Rails. Coming from a Symfony (PHP) and Django (Python)
My current project involves deploying an upgraded .exe file that runs as a Windows

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.