QPrintDialog在Windows中显示两次

时间:2013-08-21 04:21:37

标签: c++ qt qprinter

我编写了这段代码,它接受了QPlainTextEditor的内容,然后将其发送到QPrint对象,用户接受了QPrintDialog

void MainWindow::on_actionPrint_triggered()
{
    printPage = new QPrinter(QPrinter::HighResolution);
    QPrintDialog *printDialog = new QPrintDialog(printPage,this);
    printDialog->show();
    if(printDialog->exec() == QPrintDialog::Accepted){
        QPainter *painterToPrnt = new QPainter;
        painterToPrnt->begin(printPage);
        painterToPrnt->drawText(printPage->pageRect(),ui->plainTextEdit->toPlainText());
        painterToPrnt->end();
    }
}

它在KDE下工作正常(没有尝试在Gnome下),但在Windows中,每当我接受printDialog时,对话框将再次显示,如果我再次接受,它会将文本发送到打印机。

我该如何解决?

1 个答案:

答案 0 :(得分:4)

我认为只调用exec()就足够了。您可以移除show()

的来电