Fix memory leak. PrinterDialog is not deleted when close it

Change-Id: I9f0a300cdaf9803bc2ad723946ac4d0f825cc28b
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Montel Laurent 2012-11-30 12:50:53 +01:00 committed by The Qt Project
parent 930207fc1f
commit c565ef6d72
5 changed files with 16 additions and 14 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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
}

View File

@ -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);

View File

@ -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();