estanisgeyer
21st March 2012, 04:58
I need to export multiple reports to pdf, but when I use the function QPrinter::setOutputFileName the error occurs:
QPainter::begin(): Returned false
QPainter::translate: Painter not active
QPainter::setPen: Painter not active
QPainter::setRenderHint: Painter must be active to set rendering hints
See the code:
for (int i = 0; model->rowCount() > i; i++)
{
int x = model->data(model->index(i, 0), Qt::DisplayRole).toInt();
QString filename = dir.append(QDir::separator()).append(model->data(model->index(i, 1), Qt::DisplayRole).toString()).append(".pdf");
QPrinter * printer = new QPrinter(QPrinter::HighResolution);
printer->setOutputFormat(QPrinter::PdfFormat);
printer->setOrientation(QPrinter::Portrait);
printer->setPaperSize(QSizeF(210, 297), QPrinter::Millimeter);
printer->setFullPage(true);
printer->setOutputFileName(filename);
QPrintPreviewWidget * printPreview = new QPrintPreviewWidget(printer, this);
Report * r = new Report(x, this); // Report generation class
connect(printPreview, SIGNAL(paintRequested(QPrinter*)), r, SLOT(Print(QPrinter*)));
printPreview->print();
disconnect(printPreview, SIGNAL(paintRequested(QPrinter*)), r, SLOT(Print(QPrinter*)));
}
If you remove the function "printer->setOutputFileName, will work, but will send directly to the printer. How can I solve this?
Thanks,
Marcelo E. Geyer
QPainter::begin(): Returned false
QPainter::translate: Painter not active
QPainter::setPen: Painter not active
QPainter::setRenderHint: Painter must be active to set rendering hints
See the code:
for (int i = 0; model->rowCount() > i; i++)
{
int x = model->data(model->index(i, 0), Qt::DisplayRole).toInt();
QString filename = dir.append(QDir::separator()).append(model->data(model->index(i, 1), Qt::DisplayRole).toString()).append(".pdf");
QPrinter * printer = new QPrinter(QPrinter::HighResolution);
printer->setOutputFormat(QPrinter::PdfFormat);
printer->setOrientation(QPrinter::Portrait);
printer->setPaperSize(QSizeF(210, 297), QPrinter::Millimeter);
printer->setFullPage(true);
printer->setOutputFileName(filename);
QPrintPreviewWidget * printPreview = new QPrintPreviewWidget(printer, this);
Report * r = new Report(x, this); // Report generation class
connect(printPreview, SIGNAL(paintRequested(QPrinter*)), r, SLOT(Print(QPrinter*)));
printPreview->print();
disconnect(printPreview, SIGNAL(paintRequested(QPrinter*)), r, SLOT(Print(QPrinter*)));
}
If you remove the function "printer->setOutputFileName, will work, but will send directly to the printer. How can I solve this?
Thanks,
Marcelo E. Geyer