我仿照QT的DEMO里面的例子写了个导出PDF文件
#ifndef QT_NO_PRINTER
if (!fileName.isEmpty())
{
if (QFileInfo(fileName).suffix().isEmpty())
fileName.append(".pdf");
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
QFile file(fileName);
if (!file.open(QFile::WriteOnly))
{
emit Savedone(false);
return;
}
QTextDocument *test;
test = new QTextDocument(this);
QFont Font;
Font.setFamily("宋体");
test->setDefaultFont(Font);
QString a,b;
a = Summary(checkerpt.reports[0],1);
if(rpt)
{
test->setHtml(a+b);
}
else
{
test->setHtml(a+b);//a,b是字符串,是个标准的HTML页
}
test->print(&printer);
emit Savedone(true);
}
else
{
emit Savedone(false);
return;
}
#endif
}
在导出完的时候经常界面里的文字会变乱码,我指界面,不是PDF文件里的字,偶尔会中断,由于文件比较大,我这个函数是写在一个线程里面去导出文件的,防止调用导出函数的界面死掉,有没有了解问题的症结所在的给点提示,很头疼啊。。。