[Qt-interest] QWebKit, XML, XSLT, HTML, Printing

Boro Andonovski spam.vnuce at gmail.com
Fri Apr 23 23:41:09 CEST 2010


A while back I posted a question about failing to print consecutively. I was under the impression that the problem's in QWebKit or QPrinter. Well, after everybody saying that the code's OK and I tried it in a separate project, it turned out everything's ok with both QWebKit and QPrinter.
Here's the actual scenario...
I get an XSLT file and a string representation of an XML. I apply the XSLT to the XML and output it to a HTML file.
I have a QWebView that loads the outputted HTML and prints it...
Take a look at the code:

//set up libxslt
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;

//do some transformations
xsltStylesheetPtr style_sheet = xsltParseStylesheetFile((const xmlChar*)_xslt_url.toStdString().c_str());
xmlDocPtr xml_doc = xmlParseDoc((xmlChar*)_xml.toStdString().c_str());
xmlDocPtr res = xsltApplyStylesheet(style_sheet, xml_doc, 0x0);
xsltSaveResultToFilename(_tmp_url.toStdString().c_str(), res, style_sheet, 0x0);

//clean up after libxslt
xsltFreeStylesheet(style_sheet);
xmlFreeDoc(xml_doc);
xmlFreeDoc(res);
xsltCleanupGlobals();
xmlCleanupParser();

_ui.web_view->load(_tmp_url);
QPrinterInfo defPrinter = QPrinterInfo::defaultPrinter();
QPrinter printer(defPrinter); //printer's all fine, the checks are removed to clarify the code
printer.setCreator("Foo");
printer.setDocName("Bar");
printer.setNumCopies(1);
_ui.web_view->print(&printer);



First try, prints perfectly, second try the printer gets nothing, and the console gets this:
QMacPrintEngine::supportedResolutions: Unexpected error: -1
QPainter::begin(): Returned false


The problem is not specific to Mac, it happens on Linux and Windows, too.
I know this isn't quite a Qt issue, but except that dozen of lines of code, everything else in the application is Qt, so I was hoping that you guys can help me a bit?

Thanks,
Boro



More information about the Qt-interest-old mailing list