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 #ifndef QT_NO_PRINTER
QPrinter printer(QPrinter::HighResolution); QPrinter printer(QPrinter::HighResolution);
QPrintDialog *printDialog = new QPrintDialog(&printer, this); QPrintDialog printDialog(&printer, this);
//! [21] //! [22] //! [21] //! [22]
if (printDialog->exec() == QDialog::Accepted) { if (printDialog.exec() == QDialog::Accepted) {
QPainter painter(&printer); QPainter painter(&printer);
QRect rect = painter.viewport(); QRect rect = painter.viewport();
QSize size = image.size(); QSize size = image.size();

View File

@ -167,11 +167,12 @@ void MainWindow::printImage()
QPrinter printer(QPrinter::HighResolution); QPrinter printer(QPrinter::HighResolution);
QPrintDialog *dlg = new QPrintDialog(&printer, this); QPrintDialog dlg(&printer, this);
dlg->setWindowTitle(tr("Print Image")); dlg.setWindowTitle(tr("Print Image"));
if (dlg->exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted) {
return; return;
}
QPainter painter; QPainter painter;
painter.begin(&printer); painter.begin(&printer);

View File

@ -121,12 +121,12 @@ void MainWindow::print()
QTextDocument *document = textEdit->document(); QTextDocument *document = textEdit->document();
QPrinter printer; QPrinter printer;
QPrintDialog *dlg = new QPrintDialog(&printer, this); QPrintDialog dlg(&printer, this);
if (dlg->exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted) {
return; return;
}
document->print(&printer); document->print(&printer);
statusBar()->showMessage(tr("Ready"), 2000); statusBar()->showMessage(tr("Ready"), 2000);
#endif #endif
} }

View File

@ -240,12 +240,13 @@ void MainWindow::printFile()
//! [18] //! [18]
QPrinter printer; QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer, this); QPrintDialog dialog(&printer, this);
dialog->setWindowTitle(tr("Print Document")); dialog.setWindowTitle(tr("Print Document"));
if (editor->textCursor().hasSelection()) if (editor->textCursor().hasSelection())
dialog->addEnabledOption(QAbstractPrintDialog::PrintSelection); dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
if (dialog->exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted) {
return; return;
}
//! [18] //! [18]
editor->print(&printer); editor->print(&printer);

View File

@ -203,9 +203,9 @@ void ScribbleArea::print()
#ifndef QT_NO_PRINTER #ifndef QT_NO_PRINTER
QPrinter printer(QPrinter::HighResolution); QPrinter printer(QPrinter::HighResolution);
QPrintDialog *printDialog = new QPrintDialog(&printer, this); QPrintDialog printDialog(&printer, this);
//! [21] //! [22] //! [21] //! [22]
if (printDialog->exec() == QDialog::Accepted) { if (printDialog.exec() == QDialog::Accepted) {
QPainter painter(&printer); QPainter painter(&printer);
QRect rect = painter.viewport(); QRect rect = painter.viewport();
QSize size = image.size(); QSize size = image.size();