1
votes

I have a QComboBox_1 with items added (both icon and text). Then i added item to the QListWidget_1 as below from a QPushButton_1 clicked(). The QListWidget forcing to add a QListWidgetItem as a pointer value.

void MainWindow::on_QPushButton_1_clicked(){
int intSelected = ui->QComboBox_1->currentIndex();
QListWidgetItem *Itm = new QListWidgetItem(ui->QComboBox_1->itemIcon(intSelected), ui->QComboBox_1->itemText(intSelected));
ui->QListWidget_1->addItem(Itm);}

And it is working fine. But i didn't delete the pointer variable "*Itm" in any of the code (MainWindow unload or close). This will create memory leak?

I am a beginner to Qt and C++

Thanks in advance.

1

1 Answers

1
votes

No it will not. Technically it's not entirely obvious from the manual, though one definitely can suppose that.

Additionally, in the source of QListWidget.cpp you can see that items are stored inside internal QListModel class which handles deletion of them automatically in its destructor and in other cases when they are removed.