From c565ef6d72ea4b95cfc72edbb67af27f8ef35fb5 Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Fri, 30 Nov 2012 12:50:53 +0100 Subject: [PATCH] Fix memory leak. PrinterDialog is not deleted when close it Change-Id: I9f0a300cdaf9803bc2ad723946ac4d0f825cc28b Reviewed-by: David Faure --- examples/touch/fingerpaint/scribblearea.cpp | 4 ++-- examples/widgets/itemviews/pixelator/mainwindow.cpp | 7 ++++--- examples/widgets/mainwindows/dockwidgets/mainwindow.cpp | 6 +++--- examples/widgets/richtext/orderform/mainwindow.cpp | 9 +++++---- examples/widgets/widgets/scribble/scribblearea.cpp | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/touch/fingerpaint/scribblearea.cpp b/examples/touch/fingerpaint/scribblearea.cpp index b0dd719ccd..7e0c8edab1 100644 --- a/examples/touch/fingerpaint/scribblearea.cpp +++ b/examples/touch/fingerpaint/scribblearea.cpp @@ -157,9 +157,9 @@ void ScribbleArea::print() #ifndef QT_NO_PRINTER QPrinter printer(QPrinter::HighResolution); - QPrintDialog *printDialog = new QPrintDialog(&printer, this); + QPrintDialog printDialog(&printer, this); //! [21] //! [22] - if (printDialog->exec() == QDialog::Accepted) { + if (printDialog.exec() == QDialog::Accepted) { QPainter painter(&printer); QRect rect = painter.viewport(); QSize size = image.size(); diff --git a/examples/widgets/itemviews/pixelator/mainwindow.cpp b/examples/widgets/itemviews/pixelator/mainwindow.cpp index cae9711135..18c1266252 100644 --- a/examples/widgets/itemviews/pixelator/mainwindow.cpp +++ b/examples/widgets/itemviews/pixelator/mainwindow.cpp @@ -167,11 +167,12 @@ void MainWindow::printImage() QPrinter printer(QPrinter::HighResolution); - QPrintDialog *dlg = new QPrintDialog(&printer, this); - dlg->setWindowTitle(tr("Print Image")); + QPrintDialog dlg(&printer, this); + dlg.setWindowTitle(tr("Print Image")); - if (dlg->exec() != QDialog::Accepted) + if (dlg.exec() != QDialog::Accepted) { return; + } QPainter painter; painter.begin(&printer); diff --git a/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp b/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp index d3b05f0a29..4228282554 100644 --- a/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp +++ b/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp @@ -121,12 +121,12 @@ void MainWindow::print() QTextDocument *document = textEdit->document(); QPrinter printer; - QPrintDialog *dlg = new QPrintDialog(&printer, this); - if (dlg->exec() != QDialog::Accepted) + QPrintDialog dlg(&printer, this); + if (dlg.exec() != QDialog::Accepted) { return; + } document->print(&printer); - statusBar()->showMessage(tr("Ready"), 2000); #endif } diff --git a/examples/widgets/richtext/orderform/mainwindow.cpp b/examples/widgets/richtext/orderform/mainwindow.cpp index 4334e8bb71..e6e7e3bd6f 100644 --- a/examples/widgets/richtext/orderform/mainwindow.cpp +++ b/examples/widgets/richtext/orderform/mainwindow.cpp @@ -240,12 +240,13 @@ void MainWindow::printFile() //! [18] QPrinter printer; - QPrintDialog *dialog = new QPrintDialog(&printer, this); - dialog->setWindowTitle(tr("Print Document")); + QPrintDialog dialog(&printer, this); + dialog.setWindowTitle(tr("Print Document")); if (editor->textCursor().hasSelection()) - dialog->addEnabledOption(QAbstractPrintDialog::PrintSelection); - if (dialog->exec() != QDialog::Accepted) + dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection); + if (dialog.exec() != QDialog::Accepted) { return; + } //! [18] editor->print(&printer); diff --git a/examples/widgets/widgets/scribble/scribblearea.cpp b/examples/widgets/widgets/scribble/scribblearea.cpp index ad17b535f2..f5ccb52b83 100644 --- a/examples/widgets/widgets/scribble/scribblearea.cpp +++ b/examples/widgets/widgets/scribble/scribblearea.cpp @@ -203,9 +203,9 @@ void ScribbleArea::print() #ifndef QT_NO_PRINTER QPrinter printer(QPrinter::HighResolution); - QPrintDialog *printDialog = new QPrintDialog(&printer, this); + QPrintDialog printDialog(&printer, this); //! [21] //! [22] - if (printDialog->exec() == QDialog::Accepted) { + if (printDialog.exec() == QDialog::Accepted) { QPainter painter(&printer); QRect rect = painter.viewport(); QSize size = image.size();