我是否应该删除QDialogProgress 指针delete
?我已经看到在某些代码中没有删除指向堆上分配的 QDialogProgress 的指针。另外,它应该放在堆栈上吗?我见过的大多数示例都在堆栈上分配 QDialogProgress。
int f(void)
{
//The minimum and maximum is the number of steps in the operation for which this progress dialog shows progress.
//for example here 0 and 100.
QProgressDialog* progress = new QProgressDialog("Fetching data...", "Cancel", 0, 100);
progress->setAutoClose(true);
progress->setAutoReset(true);
progress->setWindowTitle
(QCoreApplication::translate("title",
"Please wait"));
progress->setMinimumDuration(1000);
for (int i = 0; i < 100; i++)
{
//set progress value.
progress->setValue(i);
}
progress->setValue(100);
//delete progress; ???????????????? is there a leak if not?
return 500;
}