chobin
17th July 2013, 15:10
Hi everyone,
I am developing a program which creates dynamically labels and saves their handles in a QList.
The labels are created OnMouse click and are destroyed OnMouse double click.
Actually the program runs without problems, but I wonder if I am doing a correct usage of pointers in order to prevent runtime errors: I would like to know if the memory correspondent to the created label pointers will exists till mouseDoubleClick_slot is called.
Here below an extract of my code.
QList<QLabel*> *tipList; // declared in the .h file
void CommandWindow::mouseRelease_slot(QMouseEvent* e)
{
QLabel *tip = new QLabel(ui->customPlot);
tipList->append(tip);
// ...
}
void CommandWindow::mouseDoubleClick_slot(QMouseEvent* e)
{
if (tipList->size())
{
for(int i=0; i<(tipList->size()); i++)
{
QLabel *tipTmp = tipList->at(i);
delete tipTmp;
}
tipList->clear();
}
}
I am developing a program which creates dynamically labels and saves their handles in a QList.
The labels are created OnMouse click and are destroyed OnMouse double click.
Actually the program runs without problems, but I wonder if I am doing a correct usage of pointers in order to prevent runtime errors: I would like to know if the memory correspondent to the created label pointers will exists till mouseDoubleClick_slot is called.
Here below an extract of my code.
QList<QLabel*> *tipList; // declared in the .h file
void CommandWindow::mouseRelease_slot(QMouseEvent* e)
{
QLabel *tip = new QLabel(ui->customPlot);
tipList->append(tip);
// ...
}
void CommandWindow::mouseDoubleClick_slot(QMouseEvent* e)
{
if (tipList->size())
{
for(int i=0; i<(tipList->size()); i++)
{
QLabel *tipTmp = tipList->at(i);
delete tipTmp;
}
tipList->clear();
}
}