QPrinter causes SIGPIPE error
-
I have a Qml application with Qt 5.4.1 and try to convert a HTML page to a PDF file.
When i start my app and call the function to convert shortly after the startup it works all fine.
But when i wait a few minutes after startup (My app does nothing else in this time, just showing the Qml ui) and then call the function, the QPrinter constructor causes a SIGPIPE - Broken Pipe error.Does anyone knows why? And how to prevent this?
bool PdfExport::exportFile(const char *path) { QWebPage page; page.mainFrame()->setContent(exportString().c_str()); printf("create printer\n"); fflush(stdout); QPrinter *printer = new QPrinter(QPrinter::HighResolution); // Causes SIGPIPE error!! printf("set printer properties\n"); fflush(stdout); printer->setPageMargins(5, 5, 5, 5, QPrinter::Millimeter); printer->setCreator(QString(this->creator.c_str())); printer->setDocName(QString(this->docName.c_str())); printer->setPageSize(QPrinter::A4); printer->setPrintRange(QPrinter::AllPages); printf("set output path\n"); fflush(stdout); printer->setOutputFileName(path); printf("print\n"); fflush(stdout); page.mainFrame()->print(printer); printf("delete printer\n"); fflush(stdout); delete printer; printf("finish\n"); fflush(stdout); return true; }
I have already added
void handler(int s) { printf("Caught SIGPIPE %d\n", s); fflush(stdout); } int main(int argc, char *argv[]) { signal(SIGPIPE, handler); struct sigaction sa; sa.sa_handler = handler; sa.sa_flags = 0; if (sigaction(SIGPIPE, &sa, 0) == -1) { printf("Could not set SIGPIPE handler\n"); } ....
in my main function. but the handler is never called...
-
Why do you create QPrinter on the heap?
One note: you are using printf() C function for debugging. With Qt you can use:
qDebug() << "SOME TEXT";
Or at least std::cout, at the end you are writing C++ code :-)
-
It should not make a difference.
You could debug into QPrinter constructor to see where exactly the problem is.